2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
9 * Copyright (C) 2013 Google Inc. All rights reserved.
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public License
22 * along with this library; see the file COPYING.LIB. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
29 #include "core/dom/DocumentInit.h"
31 #include "RuntimeEnabledFeatures.h"
32 #include "core/dom/Document.h"
33 #include "core/dom/custom/CustomElementRegistrationContext.h"
34 #include "core/html/HTMLFrameOwnerElement.h"
35 #include "core/html/HTMLImportsController.h"
36 #include "core/frame/Frame.h"
40 static Document* parentDocument(Frame* frame)
44 Element* ownerElement = frame->ownerElement();
47 return &ownerElement->document();
51 static Document* ownerDocument(Frame* frame)
56 Frame* ownerFrame = frame->tree().parent();
58 ownerFrame = frame->loader().opener();
61 return ownerFrame->document();
64 DocumentInit::DocumentInit(const KURL& url, Frame* frame, WeakPtr<Document> contextDocument, HTMLImport* import)
67 , m_parent(parentDocument(frame))
68 , m_owner(ownerDocument(frame))
69 , m_contextDocument(contextDocument)
74 DocumentInit::DocumentInit(const DocumentInit& other)
76 , m_frame(other.m_frame)
77 , m_parent(other.m_parent)
78 , m_owner(other.m_owner)
79 , m_contextDocument(other.m_contextDocument)
80 , m_import(other.m_import)
81 , m_registrationContext(other.m_registrationContext)
85 DocumentInit::~DocumentInit()
89 bool DocumentInit::shouldSetURL() const
91 Frame* frame = frameForSecurityContext();
92 return (frame && frame->ownerElement()) || !m_url.isEmpty();
95 bool DocumentInit::shouldTreatURLAsSrcdocDocument() const
97 return m_parent && m_frame->loader().shouldTreatURLAsSrcdocDocument(m_url);
100 bool DocumentInit::isSeamlessAllowedFor(Document* child) const
104 if (m_parent->isSandboxed(SandboxSeamlessIframes))
106 if (child->isSrcdocDocument())
108 if (m_parent->securityOrigin()->canAccess(child->securityOrigin()))
110 return m_parent->securityOrigin()->canRequest(child->url());
113 Frame* DocumentInit::frameForSecurityContext() const
118 return m_import->frame();
122 SandboxFlags DocumentInit::sandboxFlags() const
124 ASSERT(frameForSecurityContext());
125 return frameForSecurityContext()->loader().effectiveSandboxFlags();
128 Settings* DocumentInit::settings() const
130 ASSERT(frameForSecurityContext());
131 return frameForSecurityContext()->settings();
134 KURL DocumentInit::parentBaseURL() const
136 return m_parent->baseURL();
139 DocumentInit& DocumentInit::withRegistrationContext(CustomElementRegistrationContext* registrationContext)
141 ASSERT(!m_registrationContext);
142 m_registrationContext = registrationContext;
146 PassRefPtr<CustomElementRegistrationContext> DocumentInit::registrationContext(Document* document) const
148 if (!RuntimeEnabledFeatures::customElementsEnabled() && !RuntimeEnabledFeatures::embedderCustomElementsEnabled())
151 if (!document->isHTMLDocument() && !document->isXHTMLDocument())
154 if (m_registrationContext)
155 return m_registrationContext.get();
157 return CustomElementRegistrationContext::create();
160 WeakPtr<Document> DocumentInit::contextDocument() const
162 return m_contextDocument;
165 DocumentInit DocumentInit::fromContext(WeakPtr<Document> contextDocument, const KURL& url)
167 return DocumentInit(url, 0, contextDocument, 0);
170 } // namespace WebCore