First swipe at resolving <rdar://problem/9125145> and https://bugs.webkit.org/show_bu...
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 May 2011 21:15:46 +0000 (21:15 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 May 2011 21:15:46 +0000 (21:15 +0000)
Reviewed by Darin Adler.

Make the Document be intelligent about returning its DocumentLoader, including the possibility that
the DocumentLoader will be null.

No new tests. No change in behavior.

Instead of storing the DocumentLoader at construction and never changing it,
always calculate it based on the FrameLoader's current DocumentLoader:
* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::suggestedMIMEType):
(WebCore::Document::lastModified):
(WebCore::Document::initSecurityContext):
(WebCore::Document::updateURLForPushOrReplaceState):
(WebCore::Document::loader):
* dom/Document.h:

Null-check or ASSERT that the DocumentLoader exists (or both) depending on the scenario:
* bindings/ScriptControllerBase.cpp:
(WebCore::ScriptController::executeIfJavaScriptURL):
* html/MediaDocument.cpp:
(WebCore::MediaDocument::replaceMediaElementTimerFired):
* html/PluginDocument.cpp:
(WebCore::PluginDocumentParser::createDocumentStructure):
* platform/mac/HTMLConverter.mm:
(fileWrapperForElement):

* WebCore.exp.in:

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

Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/bindings/ScriptControllerBase.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/html/MediaDocument.cpp
Source/WebCore/html/PluginDocument.cpp
Source/WebCore/platform/mac/HTMLConverter.mm

index 58785a8..1268a29 100644 (file)
@@ -1,3 +1,37 @@
+2011-05-27  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Darin Adler.
+
+        First swipe at resolving <rdar://problem/9125145> and https://bugs.webkit.org/show_bug.cgi?id=61494
+        
+        Make the Document be intelligent about returning its DocumentLoader, including the possibility that
+        the DocumentLoader will be null.
+
+        No new tests. No change in behavior.
+
+        Instead of storing the DocumentLoader at construction and never changing it,
+        always calculate it based on the FrameLoader's current DocumentLoader:
+        * dom/Document.cpp:
+        (WebCore::Document::Document):
+        (WebCore::Document::suggestedMIMEType):
+        (WebCore::Document::lastModified):
+        (WebCore::Document::initSecurityContext):
+        (WebCore::Document::updateURLForPushOrReplaceState):
+        (WebCore::Document::loader):
+        * dom/Document.h:
+
+        Null-check or ASSERT that the DocumentLoader exists (or both) depending on the scenario:
+        * bindings/ScriptControllerBase.cpp:
+        (WebCore::ScriptController::executeIfJavaScriptURL):
+        * html/MediaDocument.cpp:
+        (WebCore::MediaDocument::replaceMediaElementTimerFired):
+        * html/PluginDocument.cpp:
+        (WebCore::PluginDocumentParser::createDocumentStructure):
+        * platform/mac/HTMLConverter.mm:
+        (fileWrapperForElement):
+
+        * WebCore.exp.in:
+
 2011-05-27  Jer Noble  <jer.noble@apple.com>
 
         Reviewed by Maciej Stachowiak.
index adf7ce0..a2e29e8 100644 (file)
@@ -1283,6 +1283,7 @@ __ZNK7WebCore8Document20cacheDocumentElementEv
 __ZNK7WebCore8Document31displayStringModifiedByEncodingERKN3WTF6StringE
 __ZNK7WebCore8Document4bodyEv
 __ZNK7WebCore8Document6domainEv
+__ZNK7WebCore8Document6loaderEv
 __ZNK7WebCore8IntPointcv7CGPointEv
 __ZNK7WebCore8IntPointcv8_NSPointEv
 __ZNK7WebCore8Position10downstreamENS_27EditingBoundaryCrossingRuleE
index 6b0e9e3..d769651 100644 (file)
@@ -114,9 +114,12 @@ bool ScriptController::executeIfJavaScriptURL(const KURL& url, ShouldReplaceDocu
     // FIXME: We should always replace the document, but doing so
     //        synchronously can cause crashes:
     //        http://bugs.webkit.org/show_bug.cgi?id=16782
-    if (shouldReplaceDocumentIfJavaScriptURL == ReplaceDocumentIfJavaScriptURL)
-        m_frame->document()->loader()->writer()->replaceDocument(scriptResult);
-
+    if (shouldReplaceDocumentIfJavaScriptURL == ReplaceDocumentIfJavaScriptURL) {
+        // We're still in a frame, so there should be a DocumentLoader.
+        ASSERT(m_frame->document()->loader());
+        if (DocumentLoader* loader = m_frame->document()->loader())
+            loader->writer()->replaceDocument(scriptResult);
+    }
     return true;
 }
 
index 2b7cc66..33212ef 100644 (file)
@@ -435,7 +435,6 @@ Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML)
     m_ignoreAutofocus = false;
 
     m_frame = frame;
-    m_documentLoader = frame ? frame->loader()->activeDocumentLoader() : 0;
 
     // We depend on the url getting immediately set in subframes, but we
     // also depend on the url NOT getting immediately set in opened windows.
@@ -1106,7 +1105,9 @@ String Document::suggestedMIMEType() const
     if (m_document->isHTMLDocument())
         return "text/html";
 
-    return m_documentLoader->responseMIMEType();
+    if (DocumentLoader* documentLoader = loader())
+        return documentLoader->responseMIMEType();
+    return String();
 }
 
 // FIXME: We need to discuss the DOM API here at some point. Ideas:
@@ -3781,7 +3782,11 @@ String Document::lastModified() const
     DateComponents date;
     bool foundDate = false;
     if (m_frame) {
-        String httpLastModified = m_documentLoader->response().httpHeaderField("Last-Modified");
+        // Since we're still in a Frame, we should have a DocumentLoader.
+        ASSERT(loader());
+        String httpLastModified;
+        if (loader()) 
+            httpLastModified = loader()->response().httpHeaderField("Last-Modified");
         if (!httpLastModified.isEmpty()) {
             date.setMillisecondsSinceEpochForDateTime(parseDate(httpLastModified));
             foundDate = true;
@@ -4510,7 +4515,11 @@ void Document::initSecurityContext()
         // load local resources.  See https://bugs.webkit.org/show_bug.cgi?id=16756
         // and https://bugs.webkit.org/show_bug.cgi?id=19760 for further
         // discussion.
-        if (m_documentLoader->substituteData().isValid())
+        
+        DocumentLoader* documentLoader = loader();
+        // Since we're still in a Frame, we should have a DocumentLoader.
+        ASSERT(documentLoader);
+        if (documentLoader && documentLoader->substituteData().isValid())
             securityOrigin()->grantLoadLocalResources();
     }
 
@@ -4591,7 +4600,10 @@ void Document::updateURLForPushOrReplaceState(const KURL& url)
 
     setURL(url);
     f->loader()->setOutgoingReferrer(url);
-    m_documentLoader->replaceRequestURLForSameDocumentNavigation(url);
+    // Since we're still in a frame, we should have a DocumentLoader.
+    ASSERT(loader());
+    if (DocumentLoader* documentLoader = loader())
+        documentLoader->replaceRequestURLForSameDocumentNavigation(url);
 }
 
 void Document::statePopped(SerializedScriptValue* stateObject)
@@ -5142,4 +5154,19 @@ void Document::didRemoveWheelEventHandler()
         mainFrame->notifyChromeClientWheelEventHandlerCountChanged();
 }
 
+DocumentLoader* Document::loader() const
+{
+    if (!m_frame)
+        return 0;
+    
+    DocumentLoader* loader = m_frame->loader()->activeDocumentLoader();
+    if (!loader)
+        return 0;
+    
+    if (m_frame->document() != this)
+        return 0;
+    
+    return loader;
+}
+
 } // namespace WebCore
index 519e695..4b1a7e7 100644 (file)
@@ -569,8 +569,7 @@ public:
     void setVisuallyOrdered();
     bool visuallyOrdered() const { return m_visuallyOrdered; }
     
-    void setDocumentLoader(DocumentLoader* documentLoader) { m_documentLoader = documentLoader; }
-    DocumentLoader* loader() const { return m_documentLoader; }
+    DocumentLoader* loader() const;
 
     void open(Document* ownerDocument = 0);
     void implicitOpen();
@@ -1174,7 +1173,6 @@ private:
     mutable RefPtr<CSSPrimitiveValueCache> m_cssPrimitiveValueCache;
 
     Frame* m_frame;
-    DocumentLoader* m_documentLoader;
     OwnPtr<CachedResourceLoader> m_cachedResourceLoader;
     RefPtr<DocumentParser> m_parser;
     bool m_wellFormed;
index ec22413..052e963 100644 (file)
@@ -221,7 +221,11 @@ void MediaDocument::replaceMediaElementTimerFired(Timer<MediaDocument>*)
         embedElement->setAttribute(heightAttr, "100%");
         embedElement->setAttribute(nameAttr, "plugin");
         embedElement->setAttribute(srcAttr, url().string());
-        embedElement->setAttribute(typeAttr, loader()->writer()->mimeType());
+
+        DocumentLoader* documentLoader = loader();
+        ASSERT(documentLoader);
+        if (documentLoader)
+            embedElement->setAttribute(typeAttr, documentLoader->writer()->mimeType());
 
         ExceptionCode ec;
         videoElement->parentNode()->replaceChild(embedElement, videoElement, ec);
index 94f44cf..6b64237 100644 (file)
@@ -92,7 +92,11 @@ void PluginDocumentParser::createDocumentStructure()
     
     m_embedElement->setAttribute(nameAttr, "plugin");
     m_embedElement->setAttribute(srcAttr, document()->url().string());
-    m_embedElement->setAttribute(typeAttr, document()->loader()->writer()->mimeType());
+    
+    DocumentLoader* loader = document()->loader();
+    ASSERT(loader);
+    if (loader)
+        m_embedElement->setAttribute(typeAttr, loader->writer()->mimeType());
 
     static_cast<PluginDocument*>(document())->setPluginNode(m_embedElement);
 
index 51f06e1..283a740 100644 (file)
@@ -1753,7 +1753,8 @@ static NSFileWrapper *fileWrapperForElement(Element* element)
     const AtomicString& attr = element->getAttribute(srcAttr);
     if (!attr.isEmpty()) {
         NSURL *URL = element->document()->completeURL(attr);
-        wrapper = fileWrapperForURL(element->document()->loader(), URL);
+        if (DocumentLoader* loader = element->document()->loader())
+            wrapper = fileWrapperForURL(loader, URL);
     }
     if (!wrapper) {
         RenderImage* renderer = toRenderImage(element->renderer());