blob: 8c508d4d27cc904ccd111e651b1aa630497dbe79 [file] [log] [blame]
Ben Murdoche69819b2013-07-17 14:56:49 +01001/*
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.
10 *
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.
15 *
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.
20 *
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.
25 *
26 */
27
28#include "config.h"
29#include "core/dom/DocumentInit.h"
30
Ben Murdoch02772c62013-07-26 10:21:05 +010031#include "RuntimeEnabledFeatures.h"
32#include "core/dom/Document.h"
Ben Murdoche69819b2013-07-17 14:56:49 +010033#include "core/html/HTMLImportsController.h"
34#include "core/page/Frame.h"
35
36namespace WebCore {
37
38bool DocumentInit::shouldSetURL() const
39{
Torne (Richard Coles)f5e4ad52013-08-05 13:57:57 +010040 Frame* frame = frameForSecurityContext();
41 return (frame && frame->ownerElement()) || !m_url.isEmpty();
Ben Murdoche69819b2013-07-17 14:56:49 +010042}
43
44bool DocumentInit::shouldTreatURLAsSrcdocDocument() const
45{
Ben Murdoch02772c62013-07-26 10:21:05 +010046 ASSERT(m_frame);
Ben Murdoche69819b2013-07-17 14:56:49 +010047 return m_frame->loader()->shouldTreatURLAsSrcdocDocument(m_url);
48}
49
Ben Murdoch02772c62013-07-26 10:21:05 +010050Frame* DocumentInit::frameForSecurityContext() const
51{
52 if (m_frame)
53 return m_frame;
54 if (m_import)
55 return m_import->frame();
56 return 0;
57}
58
Ben Murdoche69819b2013-07-17 14:56:49 +010059SandboxFlags DocumentInit::sandboxFlags() const
60{
Ben Murdoch02772c62013-07-26 10:21:05 +010061 ASSERT(frameForSecurityContext());
62 return frameForSecurityContext()->loader()->effectiveSandboxFlags();
Ben Murdoche69819b2013-07-17 14:56:49 +010063}
64
65Settings* DocumentInit::settings() const
66{
Ben Murdoch02772c62013-07-26 10:21:05 +010067 ASSERT(frameForSecurityContext());
68 return frameForSecurityContext()->settings();
Ben Murdoche69819b2013-07-17 14:56:49 +010069}
70
71Frame* DocumentInit::ownerFrame() const
72{
Ben Murdoch02772c62013-07-26 10:21:05 +010073 if (!m_frame)
74 return 0;
75
Ben Murdoche69819b2013-07-17 14:56:49 +010076 Frame* ownerFrame = m_frame->tree()->parent();
77 if (!ownerFrame)
78 ownerFrame = m_frame->loader()->opener();
79 return ownerFrame;
80}
81
Ben Murdoch02772c62013-07-26 10:21:05 +010082DocumentInit& DocumentInit::withRegistrationContext(CustomElementRegistrationContext* registrationContext)
83{
84 ASSERT(!m_registrationContext);
85 m_registrationContext = registrationContext;
86 return *this;
87}
88
89PassRefPtr<CustomElementRegistrationContext> DocumentInit::registrationContext(Document* document) const
90{
91 if (!RuntimeEnabledFeatures::customDOMElementsEnabled())
92 return 0;
93
94 if (!document->isHTMLDocument() && !document->isXHTMLDocument())
95 return 0;
96
97 if (m_registrationContext)
98 return m_registrationContext.get();
99
100 return CustomElementRegistrationContext::create();
101}
102
Ben Murdoche69819b2013-07-17 14:56:49 +0100103} // namespace WebCore
104