Skip to content
Permalink
Browse files
Reviewed by Sam.
        - refactor SecurityOrigin in preparation for merging with SecurityOriginData

        * platform/SecurityOrigin.cpp:
        (WebCore::SecurityOrigin::SecurityOrigin):
        (WebCore::SecurityOrigin::create):
        (WebCore::SecurityOrigin::createForFrame):
        * platform/SecurityOrigin.h:



Canonical link: https://commits.webkit.org/23182@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@29349 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
othermaciej committed Jan 10, 2008
1 parent 5d3dc0f commit dd439129082be06df00d9ca8f32435a7dbd563a9
Showing with 43 additions and 39 deletions.
  1. +12 −0 WebCore/ChangeLog
  2. +29 −38 WebCore/platform/SecurityOrigin.cpp
  3. +2 −1 WebCore/platform/SecurityOrigin.h
@@ -1,3 +1,15 @@
2008-01-09 Maciej Stachowiak <mjs@apple.com>

Reviewed by Sam.

- refactor SecurityOrigin in preparation for merging with SecurityOriginData

* platform/SecurityOrigin.cpp:
(WebCore::SecurityOrigin::SecurityOrigin):
(WebCore::SecurityOrigin::create):
(WebCore::SecurityOrigin::createForFrame):
* platform/SecurityOrigin.h:

2008-01-09 Ada Chan <adachan@apple.com>

Tabs with ctrl, meta, or altgraph modifier key down should not advance focus.
@@ -39,68 +39,59 @@

namespace WebCore {

SecurityOrigin::SecurityOrigin(const KURL& url)
: m_port(0)
, m_portSet(false)
SecurityOrigin::SecurityOrigin(const String& protocol, const String& host, unsigned short port)
: m_protocol(protocol.lower())
, m_host(host.lower())
, m_port(port)
, m_portSet(port)
, m_noAccess(false)
, m_domainWasSetInDOM(false)
{
if (url.isEmpty())
return;

m_protocol = url.protocol().lower();

// These protocols do not represent principals.
// These protocols do not create security origins; the owner frame provides the origin
if (m_protocol == "about" || m_protocol == "javascript")
m_protocol = String();

if (m_protocol.isEmpty())
return;

// data: URLs are not allowed access to anything other than themselves.
if (m_protocol == "data")
m_noAccess = true;

m_host = url.host().lower();
m_port = url.port();

if (m_port)
m_portSet = true;
}

bool SecurityOrigin::isEmpty() const
{
return m_protocol.isEmpty();
}

PassRefPtr<SecurityOrigin> SecurityOrigin::create(const String& protocol, const String& host, unsigned short port, SecurityOrigin* ownerFrameOrigin)
{
RefPtr<SecurityOrigin> origin = new SecurityOrigin(protocol, host, port);

// If we do not obtain a meaningful origin from the URL, then we try to find one
// via the frame hierarchy.
// We alias the SecurityOrigins to match Firefox, see Bug 15313
// http://bugs.webkit.org/show_bug.cgi?id=15313
if (origin->isEmpty() && ownerFrameOrigin)
return ownerFrameOrigin;

return origin.release();
}

PassRefPtr<SecurityOrigin> SecurityOrigin::createForFrame(Frame* frame)
{
if (!frame)
return new SecurityOrigin(KURL());
return create("", "", 0, 0);

FrameLoader* loader = frame->loader();
KURL url = loader->url();

RefPtr<SecurityOrigin> origin = new SecurityOrigin(loader->url());
if (!origin->isEmpty())
return origin;

// If we do not obtain a principal from the URL, then we try to find a
// principal via the frame hierarchy.
Frame* ownerFrame = frame->tree()->parent();
if (!ownerFrame)
ownerFrame = loader->opener();

Frame* openerFrame = frame->tree()->parent();
if (!openerFrame) {
openerFrame = loader->opener();
if (!openerFrame)
return origin;
}

Document* openerDocument = openerFrame->document();
if (!openerDocument)
return origin;
SecurityOrigin* ownerFrameOrigin = 0;
if (ownerFrame && ownerFrame->document())
ownerFrameOrigin = ownerFrame->document()->securityOrigin();

// We alias the SecurityOrigins to match Firefox, see Bug 15313
// http://bugs.webkit.org/show_bug.cgi?id=15313
return openerDocument->securityOrigin();
return create(url.protocol(), url.host(), url.port(), ownerFrameOrigin);
}

void SecurityOrigin::setDomainFromDOM(const String& newDomain)
@@ -43,6 +43,7 @@ namespace WebCore {
class SecurityOrigin : public RefCounted<SecurityOrigin> {
public:
static PassRefPtr<SecurityOrigin> createForFrame(Frame*);
static PassRefPtr<SecurityOrigin> create(const String& protocol, const String& host, unsigned short port, SecurityOrigin* ownerFrameOrigin);

void setDomainFromDOM(const String& newDomain);
String domain() const { return m_host; }
@@ -56,7 +57,7 @@ namespace WebCore {
SecurityOriginData securityOriginData() const;

private:
SecurityOrigin(const KURL& url);
SecurityOrigin(const String& protocol, const String& host, unsigned short port);

String m_protocol;
String m_host;

0 comments on commit dd43912

Please sign in to comment.