Ref-ify some functions that always succeed in constructing Documents.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 9 Aug 2015 08:11:32 +0000 (08:11 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 9 Aug 2015 08:11:32 +0000 (08:11 +0000)
<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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@188193 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/DOMImplementation.cpp
Source/WebCore/dom/DOMImplementation.h
Source/WebCore/loader/DocumentWriter.cpp
Source/WebCore/loader/DocumentWriter.h
Source/WebCore/xml/DOMParser.cpp
Source/WebCore/xml/DOMParser.h
Source/WebCore/xml/XSLTProcessor.cpp
Source/WebCore/xml/XSLTProcessor.h

index ecf5158..43c9fa5 100644 (file)
@@ -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.
index 0a5b50d..a4a3f8d 100644 (file)
@@ -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")
index baf219c..d27d8e7 100644 (file)
@@ -58,13 +58,13 @@ public:
     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);
index a1c377f..2433687 100644 (file)
@@ -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)
index e06faa0..39e5dfb 100644 (file)
@@ -68,7 +68,7 @@ public:
     void setDocumentWasLoadedAsPartOfNavigation();
 
 private:
-    PassRefPtr<Document> createDocument(const URL&);
+    Ref<Document> createDocument(const URL&);
     void clear();
 
     Frame* m_frame;
index eb43672..e4c6947 100644 (file)
@@ -25,7 +25,7 @@
 
 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"
@@ -33,12 +33,12 @@ PassRefPtr<Document> DOMParser::parseFromString(const String& str, const String&
         && 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
index ea2ebc9..132ca5b 100644 (file)
@@ -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() { }
index 491f12c..1f0958b 100644 (file)
@@ -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)
index 2bc0804..682328f 100644 (file)
@@ -46,7 +46,7 @@ public:
 
     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)