Changeset 149866 in webkit


Ignore:
Timestamp:
May 10, 2013 4:59:15 AM (11 years ago)
Author:
andersca@apple.com
Message:

Begin making SecurityOrigin immutable
https://bugs.webkit.org/show_bug.cgi?id=115898

Reviewed by Andreas Kling.

Replace SecurityOrigin::setDomainFromDOM and SecurityOrigin::grantUniversalAccess with
member functions that return new SecurityOrigin objects.

  • dom/Document.cpp:

(WebCore::Document::setDomain):
Update the security origin to one returned by copyWithDomainSetFromDOM.

(WebCore::Document::initSecurityContext):
Set the security origin to one returned by copyWithUniversalAccessGranted().

  • page/SecurityOrigin.cpp:

(WebCore::SecurityOrigin::SecurityOrigin):
Add a new constructor that takes all the member variables as parameters. This is a little unwieldy at the moment,
but all the boolean parameters could be replaced by a bitmask of flags.

(WebCore::SecurityOrigin::isolatedCopy):
Call the new constructor.

(WebCore::SecurityOrigin::copyWithDomainSetFromDOM):
Return a new security origin with m_domainWasSetInDOM set to true and the domain updated.

(WebCore::SecurityOrigin::copyWithUniversalAccessGranted):
Return a new security origin with m_universalAccess set to true.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r149865 r149866  
     12013-05-10  Anders Carlsson  <andersca@apple.com>
     2
     3        Begin making SecurityOrigin immutable
     4        https://bugs.webkit.org/show_bug.cgi?id=115898
     5
     6        Reviewed by Andreas Kling.
     7
     8        Replace SecurityOrigin::setDomainFromDOM and SecurityOrigin::grantUniversalAccess with
     9        member functions that return new SecurityOrigin objects.
     10
     11        * dom/Document.cpp:
     12        (WebCore::Document::setDomain):
     13        Update the security origin to one returned by copyWithDomainSetFromDOM.
     14   
     15        (WebCore::Document::initSecurityContext):
     16        Set the security origin to one returned by copyWithUniversalAccessGranted().
     17
     18        * page/SecurityOrigin.cpp:
     19        (WebCore::SecurityOrigin::SecurityOrigin):
     20        Add a new constructor that takes all the member variables as parameters. This is a little unwieldy at the moment,
     21        but all the boolean parameters could be replaced by a bitmask of flags.
     22
     23        (WebCore::SecurityOrigin::isolatedCopy):
     24        Call the new constructor.
     25
     26        (WebCore::SecurityOrigin::copyWithDomainSetFromDOM):
     27        Return a new security origin with m_domainWasSetInDOM set to true and the domain updated.
     28
     29        (WebCore::SecurityOrigin::copyWithUniversalAccessGranted):
     30        Return a new security origin with m_universalAccess set to true.
     31
    1322013-05-10  Anders Carlsson  <andersca@apple.com>
    233
  • trunk/Source/WebCore/dom/Document.cpp

    r149865 r149866  
    38053805
    38063806    // If the new domain is the same as the old domain, still call
    3807     // securityOrigin()->setDomainForDOM. This will change the
     3807    // securityOrigin()->copyWithDomainSetFromDOM. This will change the
    38083808    // security check behavior. For example, if a page loaded on port 8000
    38093809    // assigns its current domain using document.domain, the page will
     
    38113811    // have also assigned to access this page.
    38123812    if (equalIgnoringCase(domain(), newDomain)) {
    3813         securityOrigin()->setDomainFromDOM(newDomain);
     3813        setSecurityOrigin(securityOrigin()->copyWithDomainSetFromDOM(newDomain));
    38143814        return;
    38153815    }
     
    38383838    }
    38393839
    3840     securityOrigin()->setDomainFromDOM(newDomain);
     3840    setSecurityOrigin(securityOrigin()->copyWithDomainSetFromDOM(newDomain));
    38413841}
    38423842
     
    45984598            // Web security is turned off. We should let this document access every other document. This is used primary by testing
    45994599            // harnesses for web sites.
    4600             securityOrigin()->grantUniversalAccess();
     4600            setSecurityOrigin(securityOrigin()->copyWithUniversalAccessGranted());
    46014601        } else if (securityOrigin()->isLocal()) {
    46024602            if (settings->allowUniversalAccessFromFileURLs() || m_frame->loader()->client()->shouldForceUniversalAccessFromLocalURL(m_url)) {
    46034603                // Some clients want local URLs to have universal access, but that setting is dangerous for other clients.
    4604                 securityOrigin()->grantUniversalAccess();
     4604                setSecurityOrigin(securityOrigin()->copyWithUniversalAccessGranted());
    46054605            } else if (!settings->allowFileAccessFromFileURLs()) {
    46064606                // Some clients want local URLs to have even tighter restrictions by default, and not be able to access other local files.
  • trunk/Source/WebCore/page/SecurityOrigin.cpp

    r149854 r149866  
    157157}
    158158
    159 SecurityOrigin::SecurityOrigin(const SecurityOrigin* other)
    160     : m_protocol(other->m_protocol.isolatedCopy())
    161     , m_host(other->m_host.isolatedCopy())
    162     , m_domain(other->m_domain.isolatedCopy())
    163     , m_filePath(other->m_filePath.isolatedCopy())
    164     , m_port(other->m_port)
    165     , m_isUnique(other->m_isUnique)
    166     , m_universalAccess(other->m_universalAccess)
    167     , m_domainWasSetInDOM(other->m_domainWasSetInDOM)
    168     , m_canLoadLocalResources(other->m_canLoadLocalResources)
    169     , m_storageBlockingPolicy(other->m_storageBlockingPolicy)
    170     , m_enforceFilePathSeparation(other->m_enforceFilePathSeparation)
    171     , m_needsDatabaseIdentifierQuirkForFiles(other->m_needsDatabaseIdentifierQuirkForFiles)
     159SecurityOrigin::SecurityOrigin(const String& protocol, const String& host, const String& domain, const String& filePath, unsigned short port, bool isUnique, bool universalAccess, bool domainWasSetInDOM, bool canLoadLocalResources, StorageBlockingPolicy storageBlockingPolicy, bool enforceFilePathSeparation, bool needsDatabaseIdentifierQuirkForFiles)
     160    : m_protocol(protocol)
     161    , m_host(host)
     162    , m_domain(domain)
     163    , m_filePath(filePath)
     164    , m_port(port)
     165    , m_isUnique(isUnique)
     166    , m_universalAccess(universalAccess)
     167    , m_domainWasSetInDOM(domainWasSetInDOM)
     168    , m_canLoadLocalResources(canLoadLocalResources)
     169    , m_storageBlockingPolicy(storageBlockingPolicy)
     170    , m_enforceFilePathSeparation(enforceFilePathSeparation)
     171    , m_needsDatabaseIdentifierQuirkForFiles(needsDatabaseIdentifierQuirkForFiles)
    172172{
    173173}
     
    208208PassRefPtr<SecurityOrigin> SecurityOrigin::isolatedCopy() const
    209209{
    210     return adoptRef(new SecurityOrigin(this));
    211 }
    212 
    213 void SecurityOrigin::setDomainFromDOM(const String& newDomain)
    214 {
    215     m_domainWasSetInDOM = true;
    216     m_domain = newDomain.lower();
     210    return adoptRef(new SecurityOrigin(m_protocol.isolatedCopy(), m_host.isolatedCopy(), m_domain.isolatedCopy(), m_filePath.isolatedCopy(), m_port, m_isUnique, m_universalAccess, m_domainWasSetInDOM, m_canLoadLocalResources, m_storageBlockingPolicy, m_enforceFilePathSeparation, m_needsDatabaseIdentifierQuirkForFiles));
     211}
     212
     213PassRefPtr<SecurityOrigin> SecurityOrigin::copyWithDomainSetFromDOM(const String& newDomain) const
     214{
     215    String domain = newDomain.lower();
     216    if (m_domainWasSetInDOM && m_domain == domain)
     217        return const_cast<SecurityOrigin*>(this);
     218
     219    return adoptRef(new SecurityOrigin(m_protocol, m_host, domain, m_filePath, m_port, m_isUnique, m_universalAccess, true, m_canLoadLocalResources, m_storageBlockingPolicy, m_enforceFilePathSeparation, m_needsDatabaseIdentifierQuirkForFiles));
    217220}
    218221
     
    435438}
    436439
    437 void SecurityOrigin::grantUniversalAccess()
    438 {
    439     m_universalAccess = true;
     440PassRefPtr<SecurityOrigin> SecurityOrigin::copyWithUniversalAccessGranted() const
     441{
     442    if (m_universalAccess)
     443        return const_cast<SecurityOrigin*>(this);
     444
     445    return adoptRef(new SecurityOrigin(m_protocol, m_host, m_domain, m_filePath, m_port, m_isUnique, true, m_domainWasSetInDOM, m_canLoadLocalResources, m_storageBlockingPolicy, m_enforceFilePathSeparation, m_needsDatabaseIdentifierQuirkForFiles));
    440446}
    441447
  • trunk/Source/WebCore/page/SecurityOrigin.h

    r149854 r149866  
    7575    PassRefPtr<SecurityOrigin> isolatedCopy() const;
    7676
    77     // Set the domain property of this security origin to newDomain. This
     77    // Create a new security origin with the domain property set to newDomain. This
    7878    // function does not check whether newDomain is a suffix of the current
    7979    // domain. The caller is responsible for validating newDomain.
    80     void setDomainFromDOM(const String& newDomain);
     80    PassRefPtr<SecurityOrigin> copyWithDomainSetFromDOM(const String& newDomain) const;
    8181    bool domainWasSetInDOM() const { return m_domainWasSetInDOM; }
    8282
     
    138138    //
    139139    // WARNING: This is an extremely powerful ability. Use with caution!
    140     void grantUniversalAccess();
     140    PassRefPtr<SecurityOrigin> copyWithUniversalAccessGranted() const;
    141141
    142142    void setStorageBlockingPolicy(StorageBlockingPolicy policy) { m_storageBlockingPolicy = policy; }
     
    216216    explicit SecurityOrigin(const KURL&);
    217217    explicit SecurityOrigin(const SecurityOrigin*);
     218    SecurityOrigin(const String& protocol, const String& host, const String& domain, const String& filePath, unsigned short port, bool isUnique, bool universalAccess, bool domainWasSetInDOM, bool canLoadLocalResources, StorageBlockingPolicy, bool enforceFilePathSeparation, bool needsDatabaseIdentifierQuirkForFiles);
    218219
    219220    // FIXME: Rename this function to something more semantic.
Note: See TracChangeset for help on using the changeset viewer.