2008-06-23  Adam Barth  <abarth@webkit.org>

        Reviewed by Darin Adler.

        https://bugs.webkit.org/show_bug.cgi?id=16756

        Move isAllowedToLoadLocalResources into SecurityOrigin.

        * dom/Document.cpp:
        (WebCore::Document::Document):
        (WebCore::Document::setURL):
        (WebCore::Document::initSecurityContext):
        * dom/Document.h:
        * loader/FrameLoader.cpp:
        (WebCore::FrameLoader::canLoad):
        * platform/SecurityOrigin.cpp:
        (WebCore::SecurityOrigin::SecurityOrigin):
        (WebCore::SecurityOrigin::isLocal):
        * platform/SecurityOrigin.h:
        (WebCore::SecurityOrigin::protocol):
        (WebCore::SecurityOrigin::host):
        (WebCore::SecurityOrigin::domain):
        (WebCore::SecurityOrigin::port):
        (WebCore::SecurityOrigin::canLoadLocalResources):
        (WebCore::SecurityOrigin::grantLoadLocalResources):
        * xml/XMLHttpRequest.cpp:
        (WebCore::XMLHttpRequest::setRequestHeader):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@34753 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/dom/Document.cpp b/WebCore/dom/Document.cpp
index b16328d..8746bf4 100644
--- a/WebCore/dom/Document.cpp
+++ b/WebCore/dom/Document.cpp
@@ -287,7 +287,6 @@
     , m_accessKeyMapValid(false)
     , m_createRenderers(true)
     , m_inPageCache(false)
-    , m_isAllowedToLoadLocalResources(false)
     , m_useSecureKeyboardEntryWhenActive(false)
     , m_isXHTML(isXHTML)
     , m_numNodeListCaches(0)
@@ -1705,28 +1704,8 @@
 
     m_url = newURL;
     m_documentURI = m_url.string();
-    m_isAllowedToLoadLocalResources = shouldBeAllowedToLoadLocalResources();
     updateBaseURL();
 }
- 
-bool Document::shouldBeAllowedToLoadLocalResources() const
-{
-    if (FrameLoader::shouldTreatURLAsLocal(m_url.string()))
-        return true;
-
-    Frame* frame = this->frame();
-    if (!frame)
-        return false;
-    
-    DocumentLoader* documentLoader = frame->loader()->documentLoader();
-    if (!documentLoader)
-        return false;
-
-    if (m_url == blankURL() && frame->loader()->opener() && frame->loader()->opener()->document()->isAllowedToLoadLocalResources())
-        return true;
-    
-    return documentLoader->substituteData().isValid();
-}
 
 void Document::setBaseElementURL(const KURL& baseElementURL)
 { 
@@ -3945,6 +3924,13 @@
     m_cookieURL = url;
     m_securityOrigin = SecurityOrigin::create(url);
 
+    // If this document was loaded with substituteData, then the document can
+    // load local resources.  See https://bugs.webkit.org/show_bug.cgi?id=16756
+    // for further discussion.
+    DocumentLoader* documentLoader = m_frame->loader()->documentLoader();
+    if (documentLoader && documentLoader->substituteData().isValid())
+        m_securityOrigin->grantLoadLocalResources();
+
     if (!m_securityOrigin->isEmpty())
         return;