#include "config.h"
#include "DOMParser.h"
#include "DOMImplementation.h"
#include "SecurityOriginPolicy.h"
#include "Settings.h"
namespace WebCore {
inline DOMParser::DOMParser(Document& contextDocument)
: m_contextDocument(makeWeakPtr(contextDocument))
, m_settings(contextDocument.settings())
{
}
DOMParser::~DOMParser() = default;
Ref<DOMParser> DOMParser::create(Document& contextDocument)
{
return adoptRef(*new DOMParser(contextDocument));
}
ExceptionOr<Ref<Document>> DOMParser::parseFromString(const String& string, const String& contentType)
{
if (contentType != "text/html" && contentType != "text/xml" && contentType != "application/xml" && contentType != "application/xhtml+xml" && contentType != "image/svg+xml")
return Exception { TypeError };
auto document = DOMImplementation::createDocument(contentType, nullptr, m_settings, URL { });
if (m_contextDocument)
document->setContextDocument(*m_contextDocument.get());
document->setContent(string);
if (m_contextDocument) {
document->setURL(m_contextDocument->url());
document->setSecurityOriginPolicy(m_contextDocument->securityOriginPolicy());
}
return document;
}
}