Skip to content
Permalink
Browse files
Ref-ify some functions that always succeed in constructing Documents.
<https://webkit.org/b/147552>

Reviewed by Sam Weinig.

Update some functions involved in the construction of new Document objects
to codify that they always construct objects.

Bonus: DOMImplementation::createCSSStyleSheet().

* dom/DOMImplementation.cpp:
(WebCore::DOMImplementation::createCSSStyleSheet):
(WebCore::DOMImplementation::createHTMLDocument):
(WebCore::DOMImplementation::createDocument):
* dom/DOMImplementation.h:
* loader/DocumentWriter.cpp:
(WebCore::DocumentWriter::createDocument):
(WebCore::DocumentWriter::begin):
* loader/DocumentWriter.h:
* xml/DOMParser.cpp:
(WebCore::DOMParser::parseFromString):
* xml/DOMParser.h:
* xml/XSLTProcessor.cpp:
(WebCore::XSLTProcessor::createDocumentFromSource):
* xml/XSLTProcessor.h:


Canonical link: https://commits.webkit.org/165927@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@188193 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Andreas Kling committed Aug 9, 2015
1 parent a0de54b commit 5399647dc71bde3da1c90cd0f3a4875e73d60288
Showing 9 changed files with 55 additions and 27 deletions.
@@ -1,3 +1,31 @@
2015-08-09 Andreas Kling <akling@apple.com>

Ref-ify some functions that always succeed in constructing Documents.
<https://webkit.org/b/147552>

Reviewed by Sam Weinig.

Update some functions involved in the construction of new Document objects
to codify that they always construct objects.

Bonus: DOMImplementation::createCSSStyleSheet().

* dom/DOMImplementation.cpp:
(WebCore::DOMImplementation::createCSSStyleSheet):
(WebCore::DOMImplementation::createHTMLDocument):
(WebCore::DOMImplementation::createDocument):
* dom/DOMImplementation.h:
* loader/DocumentWriter.cpp:
(WebCore::DocumentWriter::createDocument):
(WebCore::DocumentWriter::begin):
* loader/DocumentWriter.h:
* xml/DOMParser.cpp:
(WebCore::DOMParser::parseFromString):
* xml/DOMParser.h:
* xml/XSLTProcessor.cpp:
(WebCore::XSLTProcessor::createDocumentFromSource):
* xml/XSLTProcessor.h:

2015-08-08 Commit Queue <commit-queue@webkit.org>

Unreviewed, rolling out r179871.
@@ -238,13 +238,13 @@ RefPtr<Document> DOMImplementation::createDocument(const String& namespaceURI,
return doc;
}

RefPtr<CSSStyleSheet> DOMImplementation::createCSSStyleSheet(const String&, const String& media, ExceptionCode&)
Ref<CSSStyleSheet> DOMImplementation::createCSSStyleSheet(const String&, const String& media, ExceptionCode&)
{
// FIXME: Title should be set.
// FIXME: Media could have wrong syntax, in which case we should generate an exception.
auto sheet = CSSStyleSheet::create(StyleSheetContents::create());
sheet.get().setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(media));
return WTF::move(sheet);
Ref<CSSStyleSheet> sheet = CSSStyleSheet::create(StyleSheetContents::create());
sheet->setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(media));
return sheet;
}

static inline bool isValidXMLMIMETypeChar(UChar c)
@@ -289,18 +289,18 @@ bool DOMImplementation::isTextMIMEType(const String& mimeType)
return false;
}

RefPtr<HTMLDocument> DOMImplementation::createHTMLDocument(const String& title)
Ref<HTMLDocument> DOMImplementation::createHTMLDocument(const String& title)
{
RefPtr<HTMLDocument> d = HTMLDocument::create(0, URL());
d->open();
d->write("<!doctype html><html><body></body></html>");
Ref<HTMLDocument> doc = HTMLDocument::create(nullptr, URL());
doc->open();
doc->write("<!doctype html><html><body></body></html>");
if (!title.isNull())
d->setTitle(title);
d->setSecurityOriginPolicy(m_document.securityOriginPolicy());
return d;
doc->setTitle(title);
doc->setSecurityOriginPolicy(m_document.securityOriginPolicy());
return doc;
}

RefPtr<Document> DOMImplementation::createDocument(const String& type, Frame* frame, const URL& url)
Ref<Document> DOMImplementation::createDocument(const String& type, Frame* frame, const URL& url)
{
// Plugins cannot take HTML and XHTML from us, and we don't even need to initialize the plugin database for those.
if (type == "text/html")
@@ -58,13 +58,13 @@ class DOMImplementation : public ScriptWrappable {
DOMImplementation* getInterface(const String& feature);

// From the DOMImplementationCSS interface
static RefPtr<CSSStyleSheet> createCSSStyleSheet(const String& title, const String& media, ExceptionCode&);
static Ref<CSSStyleSheet> createCSSStyleSheet(const String& title, const String& media, ExceptionCode&);

// From the HTMLDOMImplementation interface
RefPtr<HTMLDocument> createHTMLDocument(const String& title);
Ref<HTMLDocument> createHTMLDocument(const String& title);

// Other methods (not part of DOM)
static RefPtr<Document> createDocument(const String& MIMEType, Frame*, const URL&);
static Ref<Document> createDocument(const String& MIMEType, Frame*, const URL&);

WEBCORE_EXPORT static bool isXMLMIMEType(const String& MIMEType);
WEBCORE_EXPORT static bool isTextMIMEType(const String& MIMEType);
@@ -101,7 +101,7 @@ void DocumentWriter::begin()
begin(URL());
}

PassRefPtr<Document> DocumentWriter::createDocument(const URL& url)
Ref<Document> DocumentWriter::createDocument(const URL& url)
{
if (!m_frame->loader().stateMachine().isDisplayingInitialEmptyDocument() && m_frame->loader().client().shouldAlwaysUsePluginDocument(m_mimeType))
return PluginDocument::create(m_frame, url);
@@ -123,7 +123,7 @@ void DocumentWriter::begin(const URL& urlReference, bool dispatch, Document* own

// Create a new document before clearing the frame, because it may need to
// inherit an aliased security context.
RefPtr<Document> document = createDocument(url);
Ref<Document> document = createDocument(url);

// If the new document is for a Plugin but we're supposed to be sandboxed from Plugins,
// then replace the document with one whose parser will ignore the incoming data (bug 39323)
@@ -138,7 +138,7 @@ void DocumentWriter::begin(const URL& urlReference, bool dispatch, Document* own
else
document->createDOMWindow();

m_frame->loader().clear(document.get(), !shouldReuseDefaultView, !shouldReuseDefaultView);
m_frame->loader().clear(document.ptr(), !shouldReuseDefaultView, !shouldReuseDefaultView);
clear();

if (!shouldReuseDefaultView)
@@ -68,7 +68,7 @@ class DocumentWriter {
void setDocumentWasLoadedAsPartOfNavigation();

private:
PassRefPtr<Document> createDocument(const URL&);
Ref<Document> createDocument(const URL&);
void clear();

Frame* m_frame;
@@ -25,20 +25,20 @@

namespace WebCore {

PassRefPtr<Document> DOMParser::parseFromString(const String& str, const String& contentType, ExceptionCode& ec)
RefPtr<Document> DOMParser::parseFromString(const String& str, const String& contentType, ExceptionCode& ec)
{
if (contentType != "text/html"
&& contentType != "text/xml"
&& contentType != "application/xml"
&& contentType != "application/xhtml+xml"
&& contentType != "image/svg+xml") {
ec = TypeError;
return 0;
return nullptr;
}

RefPtr<Document> doc = DOMImplementation::createDocument(contentType, 0, URL());
Ref<Document> doc = DOMImplementation::createDocument(contentType, nullptr, URL());
doc->setContent(str);
return doc.release();
return WTF::move(doc);
}

} // namespace WebCore
@@ -32,7 +32,7 @@ class DOMParser : public RefCounted<DOMParser> {
public:
static Ref<DOMParser> create() { return adoptRef(*new DOMParser); }

PassRefPtr<Document> parseFromString(const String&, const String& contentType, ExceptionCode&);
RefPtr<Document> parseFromString(const String&, const String& contentType, ExceptionCode&);

private:
DOMParser() { }
@@ -68,7 +68,7 @@ XSLTProcessor::~XSLTProcessor()
ASSERT(!m_stylesheetRootNode || !m_stylesheet || m_stylesheet->hasOneRef());
}

PassRefPtr<Document> XSLTProcessor::createDocumentFromSource(const String& sourceString,
Ref<Document> XSLTProcessor::createDocumentFromSource(const String& sourceString,
const String& sourceEncoding, const String& sourceMIMEType, Node* sourceNode, Frame* frame)
{
Ref<Document> ownerDocument(sourceNode->document());
@@ -106,7 +106,7 @@ PassRefPtr<Document> XSLTProcessor::createDocumentFromSource(const String& sourc

result->setContent(documentSource);

return result.release();
return result.releaseNonNull();
}

PassRefPtr<Document> XSLTProcessor::transformToDocument(Node* sourceNode)
@@ -46,7 +46,7 @@ class XSLTProcessor : public RefCounted<XSLTProcessor> {

void setXSLStyleSheet(PassRefPtr<XSLStyleSheet> styleSheet) { m_stylesheet = styleSheet; }
bool transformToString(Node& source, String& resultMIMEType, String& resultString, String& resultEncoding);
PassRefPtr<Document> createDocumentFromSource(const String& source, const String& sourceEncoding, const String& sourceMIMEType, Node* sourceNode, Frame* frame);
Ref<Document> createDocumentFromSource(const String& source, const String& sourceEncoding, const String& sourceMIMEType, Node* sourceNode, Frame* frame);

// DOM methods
void importStylesheet(PassRefPtr<Node> style)

0 comments on commit 5399647

Please sign in to comment.