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 "core/dom/Document.h"
32 #include "core/dom/custom/CustomElementRegistrationContext.h"
33 #include "core/frame/LocalFrame.h"
34 #include "core/html/HTMLFrameOwnerElement.h"
35 #include "core/html/imports/HTMLImportsController.h"
36 #include "core/loader/DocumentLoader.h"
37 #include "platform/RuntimeEnabledFeatures.h"
38 #include "public/platform/Platform.h"
42 // FIXME: Broken with OOPI.
43 static Document
* parentDocument(LocalFrame
* frame
)
47 Element
* ownerElement
= frame
->deprecatedLocalOwner();
50 return &ownerElement
->document();
54 static Document
* ownerDocument(LocalFrame
* frame
)
59 Frame
* ownerFrame
= frame
->tree().parent();
61 ownerFrame
= frame
->loader().opener();
62 if (!ownerFrame
|| !ownerFrame
->isLocalFrame())
64 return toLocalFrame(ownerFrame
)->document();
67 DocumentInit::DocumentInit(const KURL
& url
, LocalFrame
* frame
, WeakPtrWillBeRawPtr
<Document
> contextDocument
, HTMLImportsController
* importsController
)
70 , m_parent(parentDocument(frame
))
71 , m_owner(ownerDocument(frame
))
72 , m_contextDocument(contextDocument
)
73 , m_importsController(importsController
)
74 , m_createNewRegistrationContext(false)
75 , m_shouldReuseDefaultView(frame
&& frame
->shouldReuseDefaultView(url
))
79 DocumentInit::DocumentInit(const DocumentInit
& other
)
81 , m_frame(other
.m_frame
)
82 , m_parent(other
.m_parent
)
83 , m_owner(other
.m_owner
)
84 , m_contextDocument(other
.m_contextDocument
)
85 , m_importsController(other
.m_importsController
)
86 , m_registrationContext(other
.m_registrationContext
)
87 , m_createNewRegistrationContext(other
.m_createNewRegistrationContext
)
88 , m_shouldReuseDefaultView(other
.m_shouldReuseDefaultView
)
92 DocumentInit::~DocumentInit()
96 bool DocumentInit::shouldSetURL() const
98 LocalFrame
* frame
= frameForSecurityContext();
99 return (frame
&& frame
->owner()) || !m_url
.isEmpty();
102 bool DocumentInit::shouldTreatURLAsSrcdocDocument() const
104 return m_parent
&& m_frame
->loader().shouldTreatURLAsSrcdocDocument(m_url
);
107 LocalFrame
* DocumentInit::frameForSecurityContext() const
111 if (m_importsController
)
112 return m_importsController
->master()->frame();
116 SandboxFlags
DocumentInit::sandboxFlags() const
118 ASSERT(frameForSecurityContext());
119 return frameForSecurityContext()->loader().effectiveSandboxFlags();
122 bool DocumentInit::shouldEnforceStrictMixedContentChecking() const
124 ASSERT(frameForSecurityContext());
125 return frameForSecurityContext()->loader().shouldEnforceStrictMixedContentChecking();
128 SecurityContext::InsecureRequestsPolicy
DocumentInit::insecureRequestsPolicy() const
130 ASSERT(frameForSecurityContext());
131 return frameForSecurityContext()->loader().insecureRequestsPolicy();
134 SecurityContext::InsecureNavigationsSet
* DocumentInit::insecureNavigationsToUpgrade() const
136 ASSERT(frameForSecurityContext());
137 return frameForSecurityContext()->loader().insecureNavigationsToUpgrade();
140 bool DocumentInit::isHostedInReservedIPRange() const
142 if (LocalFrame
* frame
= frameForSecurityContext()) {
143 if (DocumentLoader
* loader
= frame
->loader().provisionalDocumentLoader() ? frame
->loader().provisionalDocumentLoader() : frame
->loader().documentLoader()) {
144 if (!loader
->response().remoteIPAddress().isEmpty())
145 return Platform::current()->isReservedIPAddress(loader
->response().remoteIPAddress());
151 Settings
* DocumentInit::settings() const
153 ASSERT(frameForSecurityContext());
154 return frameForSecurityContext()->settings();
157 KURL
DocumentInit::parentBaseURL() const
159 return m_parent
->baseURL();
162 DocumentInit
& DocumentInit::withRegistrationContext(CustomElementRegistrationContext
* registrationContext
)
164 ASSERT(!m_createNewRegistrationContext
&& !m_registrationContext
);
165 m_registrationContext
= registrationContext
;
169 DocumentInit
& DocumentInit::withNewRegistrationContext()
171 ASSERT(!m_createNewRegistrationContext
&& !m_registrationContext
);
172 m_createNewRegistrationContext
= true;
176 PassRefPtrWillBeRawPtr
<CustomElementRegistrationContext
> DocumentInit::registrationContext(Document
* document
) const
178 if (!document
->isHTMLDocument() && !document
->isXHTMLDocument())
181 if (m_createNewRegistrationContext
)
182 return CustomElementRegistrationContext::create();
184 return m_registrationContext
.get();
187 WeakPtrWillBeRawPtr
<Document
> DocumentInit::contextDocument() const
189 return m_contextDocument
;
192 DocumentInit
DocumentInit::fromContext(WeakPtrWillBeRawPtr
<Document
> contextDocument
, const KURL
& url
)
194 return DocumentInit(url
, 0, contextDocument
, 0);