summaryrefslogtreecommitdiff
path: root/Source/WebCore/inspector/DOMEditor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/inspector/DOMEditor.cpp')
-rw-r--r--Source/WebCore/inspector/DOMEditor.cpp364
1 files changed, 170 insertions, 194 deletions
diff --git a/Source/WebCore/inspector/DOMEditor.cpp b/Source/WebCore/inspector/DOMEditor.cpp
index 7f2fab8bb..5e5707e80 100644
--- a/Source/WebCore/inspector/DOMEditor.cpp
+++ b/Source/WebCore/inspector/DOMEditor.cpp
@@ -29,15 +29,12 @@
*/
#include "config.h"
-
-#if ENABLE(INSPECTOR)
-
#include "DOMEditor.h"
#include "DOMPatchSupport.h"
#include "Document.h"
#include "Element.h"
-#include "ExceptionCode.h"
+#include "ExceptionCodeDescription.h"
#include "InspectorHistory.h"
#include "Node.h"
#include "Text.h"
@@ -46,411 +43,390 @@
namespace WebCore {
-class DOMEditor::RemoveChildAction : public InspectorHistory::Action {
+class DOMEditor::RemoveChildAction final : public InspectorHistory::Action {
WTF_MAKE_NONCOPYABLE(RemoveChildAction);
public:
- RemoveChildAction(Node* parentNode, Node* node)
- : InspectorHistory::Action("RemoveChild")
+ RemoveChildAction(Node& parentNode, Node& node)
+ : Action("RemoveChild")
, m_parentNode(parentNode)
, m_node(node)
{
}
- virtual bool perform(ExceptionCode& ec) override
+ ExceptionOr<void> perform() final
{
m_anchorNode = m_node->nextSibling();
- return redo(ec);
+ return redo();
}
- virtual bool undo(ExceptionCode& ec) override
+ ExceptionOr<void> undo() final
{
- return m_parentNode->insertBefore(m_node.get(), m_anchorNode.get(), ec);
+ return m_parentNode->insertBefore(m_node, m_anchorNode.get());
}
- virtual bool redo(ExceptionCode& ec) override
+ ExceptionOr<void> redo() final
{
- return m_parentNode->removeChild(m_node.get(), ec);
+ return m_parentNode->removeChild(m_node);
}
private:
- RefPtr<Node> m_parentNode;
- RefPtr<Node> m_node;
+ Ref<Node> m_parentNode;
+ Ref<Node> m_node;
RefPtr<Node> m_anchorNode;
};
-class DOMEditor::InsertBeforeAction : public InspectorHistory::Action {
- WTF_MAKE_NONCOPYABLE(InsertBeforeAction);
+class DOMEditor::InsertBeforeAction final : public InspectorHistory::Action {
public:
- InsertBeforeAction(Node* parentNode, PassRefPtr<Node> node, Node* anchorNode)
- : InspectorHistory::Action("InsertBefore")
+ InsertBeforeAction(Node& parentNode, Ref<Node>&& node, Node* anchorNode)
+ : Action("InsertBefore")
, m_parentNode(parentNode)
- , m_node(node)
+ , m_node(WTFMove(node))
, m_anchorNode(anchorNode)
{
}
- virtual bool perform(ExceptionCode& ec) override
+private:
+ ExceptionOr<void> perform() final
{
if (m_node->parentNode()) {
- m_removeChildAction = adoptPtr(new RemoveChildAction(m_node->parentNode(), m_node.get()));
- if (!m_removeChildAction->perform(ec))
- return false;
+ m_removeChildAction = std::make_unique<RemoveChildAction>(*m_node->parentNode(), m_node);
+ auto result = m_removeChildAction->perform();
+ if (result.hasException())
+ return result.releaseException();
}
- return m_parentNode->insertBefore(m_node.get(), m_anchorNode.get(), ec);
+ return m_parentNode->insertBefore(m_node, m_anchorNode.get());
}
- virtual bool undo(ExceptionCode& ec) override
+ ExceptionOr<void> undo() final
{
- if (!m_parentNode->removeChild(m_node.get(), ec))
- return false;
- if (m_removeChildAction)
- return m_removeChildAction->undo(ec);
- return true;
+ auto result = m_parentNode->removeChild(m_node);
+ if (result.hasException())
+ return result.releaseException();
+ if (!m_removeChildAction)
+ return { };
+ return m_removeChildAction->undo();
}
- virtual bool redo(ExceptionCode& ec) override
+ ExceptionOr<void> redo() final
{
- if (m_removeChildAction && !m_removeChildAction->redo(ec))
- return false;
- return m_parentNode->insertBefore(m_node.get(), m_anchorNode.get(), ec);
+ if (m_removeChildAction) {
+ auto result = m_removeChildAction->redo();
+ if (result.hasException())
+ return result.releaseException();
+ }
+ return m_parentNode->insertBefore(m_node, m_anchorNode.get());
}
-private:
- RefPtr<Node> m_parentNode;
- RefPtr<Node> m_node;
+ Ref<Node> m_parentNode;
+ Ref<Node> m_node;
RefPtr<Node> m_anchorNode;
- OwnPtr<RemoveChildAction> m_removeChildAction;
+ std::unique_ptr<RemoveChildAction> m_removeChildAction;
};
-class DOMEditor::RemoveAttributeAction : public InspectorHistory::Action {
+class DOMEditor::RemoveAttributeAction final : public InspectorHistory::Action {
WTF_MAKE_NONCOPYABLE(RemoveAttributeAction);
public:
- RemoveAttributeAction(Element* element, const String& name)
- : InspectorHistory::Action("RemoveAttribute")
+ RemoveAttributeAction(Element& element, const String& name)
+ : Action("RemoveAttribute")
, m_element(element)
, m_name(name)
{
}
- virtual bool perform(ExceptionCode& ec) override
+private:
+ ExceptionOr<void> perform() final
{
m_value = m_element->getAttribute(m_name);
- return redo(ec);
+ return redo();
}
- virtual bool undo(ExceptionCode& ec) override
+ ExceptionOr<void> undo() final
{
- m_element->setAttribute(m_name, m_value, ec);
- return true;
+ return m_element->setAttribute(m_name, m_value);
}
- virtual bool redo(ExceptionCode&) override
+ ExceptionOr<void> redo() final
{
m_element->removeAttribute(m_name);
- return true;
+ return { };
}
-private:
- RefPtr<Element> m_element;
+ Ref<Element> m_element;
String m_name;
String m_value;
};
-class DOMEditor::SetAttributeAction : public InspectorHistory::Action {
+class DOMEditor::SetAttributeAction final : public InspectorHistory::Action {
WTF_MAKE_NONCOPYABLE(SetAttributeAction);
public:
- SetAttributeAction(Element* element, const String& name, const String& value)
- : InspectorHistory::Action("SetAttribute")
+ SetAttributeAction(Element& element, const AtomicString& name, const AtomicString& value)
+ : Action("SetAttribute")
, m_element(element)
, m_name(name)
, m_value(value)
- , m_hadAttribute(false)
{
}
- virtual bool perform(ExceptionCode& ec) override
+private:
+ ExceptionOr<void> perform() final
{
- m_hadAttribute = m_element->hasAttribute(m_name);
- if (m_hadAttribute)
- m_oldValue = m_element->getAttribute(m_name);
- return redo(ec);
+ m_oldValue = m_element->getAttribute(m_name);
+ return redo();
}
- virtual bool undo(ExceptionCode& ec) override
+ ExceptionOr<void> undo() final
{
- if (m_hadAttribute)
- m_element->setAttribute(m_name, m_oldValue, ec);
- else
+ if (m_oldValue.isNull()) {
m_element->removeAttribute(m_name);
- return true;
+ return { };
+ }
+ return m_element->setAttribute(m_name, m_oldValue);
}
- virtual bool redo(ExceptionCode& ec) override
+ ExceptionOr<void> redo() final
{
- m_element->setAttribute(m_name, m_value, ec);
- return true;
+ return m_element->setAttribute(m_name, m_value);
}
-private:
- RefPtr<Element> m_element;
- String m_name;
- String m_value;
- bool m_hadAttribute;
- String m_oldValue;
+ Ref<Element> m_element;
+ AtomicString m_name;
+ AtomicString m_value;
+ AtomicString m_oldValue;
};
-class DOMEditor::SetOuterHTMLAction : public InspectorHistory::Action {
- WTF_MAKE_NONCOPYABLE(SetOuterHTMLAction);
+class DOMEditor::SetOuterHTMLAction final : public InspectorHistory::Action {
public:
SetOuterHTMLAction(Node& node, const String& html)
- : InspectorHistory::Action("SetOuterHTML")
+ : Action("SetOuterHTML")
, m_node(node)
, m_nextSibling(node.nextSibling())
, m_html(html)
- , m_newNode(nullptr)
- , m_history(adoptPtr(new InspectorHistory()))
- , m_domEditor(adoptPtr(new DOMEditor(m_history.get())))
{
}
- virtual bool perform(ExceptionCode& ec) override
+ Node* newNode() const
{
- m_oldHTML = createMarkup(m_node.get());
- DOMPatchSupport domPatchSupport(m_domEditor.get(), &m_node->document());
- m_newNode = domPatchSupport.patchNode(m_node.get(), m_html, ec);
- return !ec;
+ return m_newNode.get();
}
- virtual bool undo(ExceptionCode& ec) override
+private:
+ ExceptionOr<void> perform() final
{
- return m_history->undo(ec);
+ m_oldHTML = createMarkup(m_node.get());
+ auto result = DOMPatchSupport { m_domEditor, m_node->document() }.patchNode(m_node, m_html);
+ if (result.hasException())
+ return result.releaseException();
+ m_newNode = result.releaseReturnValue();
+ return { };
}
- virtual bool redo(ExceptionCode& ec) override
+ ExceptionOr<void> undo() final
{
- return m_history->redo(ec);
+ return m_history.undo();
}
- Node* newNode()
+ ExceptionOr<void> redo() final
{
- return m_newNode;
+ return m_history.redo();
}
-private:
Ref<Node> m_node;
RefPtr<Node> m_nextSibling;
String m_html;
String m_oldHTML;
- Node* m_newNode;
- OwnPtr<InspectorHistory> m_history;
- OwnPtr<DOMEditor> m_domEditor;
+ RefPtr<Node> m_newNode { nullptr };
+ InspectorHistory m_history;
+ DOMEditor m_domEditor { m_history };
};
-class DOMEditor::ReplaceWholeTextAction : public InspectorHistory::Action {
+class DOMEditor::ReplaceWholeTextAction final : public InspectorHistory::Action {
WTF_MAKE_NONCOPYABLE(ReplaceWholeTextAction);
public:
- ReplaceWholeTextAction(Text* textNode, const String& text)
- : InspectorHistory::Action("ReplaceWholeText")
+ ReplaceWholeTextAction(Text& textNode, const String& text)
+ : Action("ReplaceWholeText")
, m_textNode(textNode)
, m_text(text)
{
}
- virtual bool perform(ExceptionCode& ec) override
+private:
+ ExceptionOr<void> perform() final
{
m_oldText = m_textNode->wholeText();
- return redo(ec);
+ return redo();
}
- virtual bool undo(ExceptionCode& ec) override
+ ExceptionOr<void> undo() final
{
- m_textNode->replaceWholeText(m_oldText, ec);
- return true;
+ m_textNode->replaceWholeText(m_oldText);
+ return { };
}
- virtual bool redo(ExceptionCode& ec) override
+ ExceptionOr<void> redo() final
{
- m_textNode->replaceWholeText(m_text, ec);
- return true;
+ m_textNode->replaceWholeText(m_text);
+ return { };
}
-private:
- RefPtr<Text> m_textNode;
+ Ref<Text> m_textNode;
String m_text;
String m_oldText;
};
-class DOMEditor::ReplaceChildNodeAction : public InspectorHistory::Action {
+class DOMEditor::ReplaceChildNodeAction final: public InspectorHistory::Action {
WTF_MAKE_NONCOPYABLE(ReplaceChildNodeAction);
public:
- ReplaceChildNodeAction(Node* parentNode, PassRefPtr<Node> newNode, Node* oldNode)
- : InspectorHistory::Action("ReplaceChildNode")
+ ReplaceChildNodeAction(Node& parentNode, Ref<Node>&& newNode, Node& oldNode)
+ : Action("ReplaceChildNode")
, m_parentNode(parentNode)
- , m_newNode(newNode)
+ , m_newNode(WTFMove(newNode))
, m_oldNode(oldNode)
{
}
- virtual bool perform(ExceptionCode& ec) override
+private:
+ ExceptionOr<void> perform() final
{
- return redo(ec);
+ return redo();
}
- virtual bool undo(ExceptionCode& ec) override
+ ExceptionOr<void> undo() final
{
- return m_parentNode->replaceChild(m_oldNode, m_newNode.get(), ec);
+ return m_parentNode->replaceChild(m_oldNode, m_newNode);
}
- virtual bool redo(ExceptionCode& ec) override
+ ExceptionOr<void> redo() final
{
- return m_parentNode->replaceChild(m_newNode, m_oldNode.get(), ec);
+ return m_parentNode->replaceChild(m_newNode, m_oldNode);
}
-private:
- RefPtr<Node> m_parentNode;
- RefPtr<Node> m_newNode;
- RefPtr<Node> m_oldNode;
+ Ref<Node> m_parentNode;
+ Ref<Node> m_newNode;
+ Ref<Node> m_oldNode;
};
-class DOMEditor::SetNodeValueAction : public InspectorHistory::Action {
+class DOMEditor::SetNodeValueAction final : public InspectorHistory::Action {
WTF_MAKE_NONCOPYABLE(SetNodeValueAction);
public:
- SetNodeValueAction(Node* node, const String& value)
- : InspectorHistory::Action("SetNodeValue")
+ SetNodeValueAction(Node& node, const String& value)
+ : Action("SetNodeValue")
, m_node(node)
, m_value(value)
{
}
- virtual bool perform(ExceptionCode& ec) override
+private:
+ ExceptionOr<void> perform() final
{
m_oldValue = m_node->nodeValue();
- return redo(ec);
+ return redo();
}
- virtual bool undo(ExceptionCode& ec) override
+ ExceptionOr<void> undo() final
{
- m_node->setNodeValue(m_oldValue, ec);
- return !ec;
+ return m_node->setNodeValue(m_oldValue);
}
- virtual bool redo(ExceptionCode& ec) override
+ ExceptionOr<void> redo() final
{
- m_node->setNodeValue(m_value, ec);
- return !ec;
+ return m_node->setNodeValue(m_value);
}
-private:
- RefPtr<Node> m_node;
+ Ref<Node> m_node;
String m_value;
String m_oldValue;
};
-DOMEditor::DOMEditor(InspectorHistory* history) : m_history(history) { }
+DOMEditor::DOMEditor(InspectorHistory& history)
+ : m_history(history)
+{
+}
-DOMEditor::~DOMEditor() { }
+DOMEditor::~DOMEditor()
+{
+}
-bool DOMEditor::insertBefore(Node* parentNode, PassRefPtr<Node> node, Node* anchorNode, ExceptionCode& ec)
+ExceptionOr<void> DOMEditor::insertBefore(Node& parentNode, Ref<Node>&& node, Node* anchorNode)
{
- return m_history->perform(adoptPtr(new InsertBeforeAction(parentNode, node, anchorNode)), ec);
+ return m_history.perform(std::make_unique<InsertBeforeAction>(parentNode, WTFMove(node), anchorNode));
}
-bool DOMEditor::removeChild(Node* parentNode, Node* node, ExceptionCode& ec)
+ExceptionOr<void> DOMEditor::removeChild(Node& parentNode, Node& node)
{
- return m_history->perform(adoptPtr(new RemoveChildAction(parentNode, node)), ec);
+ return m_history.perform(std::make_unique<RemoveChildAction>(parentNode, node));
}
-bool DOMEditor::setAttribute(Element* element, const String& name, const String& value, ExceptionCode& ec)
+ExceptionOr<void> DOMEditor::setAttribute(Element& element, const String& name, const String& value)
{
- return m_history->perform(adoptPtr(new SetAttributeAction(element, name, value)), ec);
+ return m_history.perform(std::make_unique<SetAttributeAction>(element, name, value));
}
-bool DOMEditor::removeAttribute(Element* element, const String& name, ExceptionCode& ec)
+ExceptionOr<void> DOMEditor::removeAttribute(Element& element, const String& name)
{
- return m_history->perform(adoptPtr(new RemoveAttributeAction(element, name)), ec);
+ return m_history.perform(std::make_unique<RemoveAttributeAction>(element, name));
}
-bool DOMEditor::setOuterHTML(Node& node, const String& html, Node** newNode, ExceptionCode& ec)
+ExceptionOr<void> DOMEditor::setOuterHTML(Node& node, const String& html, Node*& newNode)
{
- OwnPtr<SetOuterHTMLAction> action = adoptPtr(new SetOuterHTMLAction(node, html));
- SetOuterHTMLAction* rawAction = action.get();
- bool result = m_history->perform(action.release(), ec);
- if (result)
- *newNode = rawAction->newNode();
+ auto action = std::make_unique<SetOuterHTMLAction>(node, html);
+ auto& rawAction = *action;
+ auto result = m_history.perform(WTFMove(action));
+ if (!result.hasException())
+ newNode = rawAction.newNode();
return result;
}
-bool DOMEditor::replaceWholeText(Text* textNode, const String& text, ExceptionCode& ec)
+ExceptionOr<void> DOMEditor::replaceWholeText(Text& textNode, const String& text)
{
- return m_history->perform(adoptPtr(new ReplaceWholeTextAction(textNode, text)), ec);
+ return m_history.perform(std::make_unique<ReplaceWholeTextAction>(textNode, text));
}
-bool DOMEditor::replaceChild(Node* parentNode, PassRefPtr<Node> newNode, Node* oldNode, ExceptionCode& ec)
+ExceptionOr<void> DOMEditor::replaceChild(Node& parentNode, Ref<Node>&& newNode, Node& oldNode)
{
- return m_history->perform(adoptPtr(new ReplaceChildNodeAction(parentNode, newNode, oldNode)), ec);
+ return m_history.perform(std::make_unique<ReplaceChildNodeAction>(parentNode, WTFMove(newNode), oldNode));
}
-bool DOMEditor::setNodeValue(Node* node, const String& value, ExceptionCode& ec)
+ExceptionOr<void> DOMEditor::setNodeValue(Node& node, const String& value)
{
- return m_history->perform(adoptPtr(new SetNodeValueAction(node, value)), ec);
+ return m_history.perform(std::make_unique<SetNodeValueAction>(node, value));
}
-static void populateErrorString(const ExceptionCode& ec, ErrorString* errorString)
+static bool populateErrorString(ExceptionOr<void>&& result, ErrorString& errorString)
{
- if (ec) {
- ExceptionCodeDescription description(ec);
- *errorString = description.name;
- }
+ if (!result.hasException())
+ return true;
+ errorString = ExceptionCodeDescription { result.releaseException().code() }.name;
+ return false;
}
-bool DOMEditor::insertBefore(Node* parentNode, PassRefPtr<Node> node, Node* anchorNode, ErrorString* errorString)
+bool DOMEditor::insertBefore(Node& parentNode, Ref<Node>&& node, Node* anchorNode, ErrorString& errorString)
{
- ExceptionCode ec = 0;
- bool result = insertBefore(parentNode, node, anchorNode, ec);
- populateErrorString(ec, errorString);
- return result;
+ return populateErrorString(insertBefore(parentNode, WTFMove(node), anchorNode), errorString);
}
-bool DOMEditor::removeChild(Node* parentNode, Node* node, ErrorString* errorString)
+bool DOMEditor::removeChild(Node& parentNode, Node& node, ErrorString& errorString)
{
- ExceptionCode ec = 0;
- bool result = removeChild(parentNode, node, ec);
- populateErrorString(ec, errorString);
- return result;
+ return populateErrorString(removeChild(parentNode, node), errorString);
}
-bool DOMEditor::setAttribute(Element* element, const String& name, const String& value, ErrorString* errorString)
+bool DOMEditor::setAttribute(Element& element, const String& name, const String& value, ErrorString& errorString)
{
- ExceptionCode ec = 0;
- bool result = setAttribute(element, name, value, ec);
- populateErrorString(ec, errorString);
- return result;
+ return populateErrorString(setAttribute(element, name, value), errorString);
}
-bool DOMEditor::removeAttribute(Element* element, const String& name, ErrorString* errorString)
+bool DOMEditor::removeAttribute(Element& element, const String& name, ErrorString& errorString)
{
- ExceptionCode ec = 0;
- bool result = removeAttribute(element, name, ec);
- populateErrorString(ec, errorString);
- return result;
+ return populateErrorString(removeAttribute(element, name), errorString);
}
-bool DOMEditor::setOuterHTML(Node& node, const String& html, Node** newNode, ErrorString* errorString)
+bool DOMEditor::setOuterHTML(Node& node, const String& html, Node*& newNode, ErrorString& errorString)
{
- ExceptionCode ec = 0;
- bool result = setOuterHTML(node, html, newNode, ec);
- populateErrorString(ec, errorString);
- return result;
+ return populateErrorString(setOuterHTML(node, html, newNode), errorString);
}
-bool DOMEditor::replaceWholeText(Text* textNode, const String& text, ErrorString* errorString)
+bool DOMEditor::replaceWholeText(Text& textNode, const String& text, ErrorString& errorString)
{
- ExceptionCode ec = 0;
- bool result = replaceWholeText(textNode, text, ec);
- populateErrorString(ec, errorString);
- return result;
+ return populateErrorString(replaceWholeText(textNode, text), errorString);
}
} // namespace WebCore
-
-#endif // ENABLE(INSPECTOR)