1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 4 * (C) 2001 Dirk Mueller (mueller (at) kde.org) 5 * (C) 2006 Alexey Proskuryakov (ap (at) 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 31 #include "RuntimeEnabledFeatures.h" 32 #include "core/dom/Document.h" 33 #include "core/html/HTMLImportsController.h" 34 #include "core/page/Frame.h" 35 36 namespace WebCore { 37 38 bool DocumentInit::shouldSetURL() const 39 { 40 Frame* frame = frameForSecurityContext(); 41 return (frame && frame->ownerElement()) || !m_url.isEmpty(); 42 } 43 44 bool DocumentInit::shouldTreatURLAsSrcdocDocument() const 45 { 46 ASSERT(m_frame); 47 return m_frame->loader()->shouldTreatURLAsSrcdocDocument(m_url); 48 } 49 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 59 SandboxFlags DocumentInit::sandboxFlags() const 60 { 61 ASSERT(frameForSecurityContext()); 62 return frameForSecurityContext()->loader()->effectiveSandboxFlags(); 63 } 64 65 Settings* DocumentInit::settings() const 66 { 67 ASSERT(frameForSecurityContext()); 68 return frameForSecurityContext()->settings(); 69 } 70 71 Frame* DocumentInit::ownerFrame() const 72 { 73 if (!m_frame) 74 return 0; 75 76 Frame* ownerFrame = m_frame->tree()->parent(); 77 if (!ownerFrame) 78 ownerFrame = m_frame->loader()->opener(); 79 return ownerFrame; 80 } 81 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() && !RuntimeEnabledFeatures::embedderCustomElementsEnabled()) 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 103 } // namespace WebCore 104 105