Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 1 | /* |
| 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 Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 31 | #include "RuntimeEnabledFeatures.h" |
| 32 | #include "core/dom/Document.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 33 | #include "core/html/HTMLImportsController.h" |
| 34 | #include "core/page/Frame.h" |
| 35 | |
| 36 | namespace WebCore { |
| 37 | |
| 38 | bool DocumentInit::shouldSetURL() const |
| 39 | { |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 40 | Frame* frame = frameForSecurityContext(); |
| 41 | return (frame && frame->ownerElement()) || !m_url.isEmpty(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | bool DocumentInit::shouldTreatURLAsSrcdocDocument() const |
| 45 | { |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 46 | ASSERT(m_frame); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 47 | return m_frame->loader()->shouldTreatURLAsSrcdocDocument(m_url); |
| 48 | } |
| 49 | |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 50 | Frame* 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 Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 59 | SandboxFlags DocumentInit::sandboxFlags() const |
| 60 | { |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 61 | ASSERT(frameForSecurityContext()); |
| 62 | return frameForSecurityContext()->loader()->effectiveSandboxFlags(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | Settings* DocumentInit::settings() const |
| 66 | { |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 67 | ASSERT(frameForSecurityContext()); |
| 68 | return frameForSecurityContext()->settings(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | Frame* DocumentInit::ownerFrame() const |
| 72 | { |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 73 | if (!m_frame) |
| 74 | return 0; |
| 75 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 76 | Frame* ownerFrame = m_frame->tree()->parent(); |
| 77 | if (!ownerFrame) |
| 78 | ownerFrame = m_frame->loader()->opener(); |
| 79 | return ownerFrame; |
| 80 | } |
| 81 | |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 82 | DocumentInit& DocumentInit::withRegistrationContext(CustomElementRegistrationContext* registrationContext) |
| 83 | { |
| 84 | ASSERT(!m_registrationContext); |
| 85 | m_registrationContext = registrationContext; |
| 86 | return *this; |
| 87 | } |
| 88 | |
| 89 | PassRefPtr<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 Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 103 | } // namespace WebCore |
| 104 | |