Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: Source/core/dom/Document.cpp

Issue 559503002: CSP: Move policy parsing out of Document. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Reworking. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/frame/csp/ContentSecurityPolicy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 4751 matching lines...) Expand 10 before | Expand all | Expand 10 after
4762 bool Document::useSecureKeyboardEntryWhenActive() const 4762 bool Document::useSecureKeyboardEntryWhenActive() const
4763 { 4763 {
4764 return m_useSecureKeyboardEntryWhenActive; 4764 return m_useSecureKeyboardEntryWhenActive;
4765 } 4765 }
4766 4766
4767 void Document::initSecurityContext() 4767 void Document::initSecurityContext()
4768 { 4768 {
4769 initSecurityContext(DocumentInit(m_url, m_frame, contextDocument(), m_import sController)); 4769 initSecurityContext(DocumentInit(m_url, m_frame, contextDocument(), m_import sController));
4770 } 4770 }
4771 4771
4772 static PassRefPtr<ContentSecurityPolicy> contentSecurityPolicyFor(Document* docu ment)
4773 {
4774 if (document->importsController())
4775 return document->importsController()->master()->contentSecurityPolicy();
4776 return ContentSecurityPolicy::create(document);
4777 }
4778
4779 void Document::initSecurityContext(const DocumentInit& initializer) 4772 void Document::initSecurityContext(const DocumentInit& initializer)
4780 { 4773 {
4781 if (haveInitializedSecurityOrigin()) { 4774 if (haveInitializedSecurityOrigin()) {
4782 ASSERT(securityOrigin()); 4775 ASSERT(securityOrigin());
4783 return; 4776 return;
4784 } 4777 }
4785 4778
4786 if (!initializer.hasSecurityContext()) { 4779 if (!initializer.hasSecurityContext()) {
4787 // No source for a security context. 4780 // No source for a security context.
4788 // This can occur via document.implementation.createDocument(). 4781 // This can occur via document.implementation.createDocument().
4789 m_cookieURL = KURL(ParsedURLString, emptyString()); 4782 m_cookieURL = KURL(ParsedURLString, emptyString());
4790 setSecurityOrigin(SecurityOrigin::createUnique()); 4783 setSecurityOrigin(SecurityOrigin::createUnique());
4791 setContentSecurityPolicy(ContentSecurityPolicy::create(this)); 4784 initContentSecurityPolicy();
4792 return; 4785 return;
4793 } 4786 }
4794 4787
4795 // In the common case, create the security context from the currently 4788 // In the common case, create the security context from the currently
4796 // loading URL with a fresh content security policy. 4789 // loading URL with a fresh content security policy.
4797 m_cookieURL = m_url; 4790 m_cookieURL = m_url;
4798 enforceSandboxFlags(initializer.sandboxFlags()); 4791 enforceSandboxFlags(initializer.sandboxFlags());
4799 setSecurityOrigin(isSandboxed(SandboxOrigin) ? SecurityOrigin::createUnique( ) : SecurityOrigin::create(m_url)); 4792 setSecurityOrigin(isSandboxed(SandboxOrigin) ? SecurityOrigin::createUnique( ) : SecurityOrigin::create(m_url));
4800 setContentSecurityPolicy(contentSecurityPolicyFor(this)); 4793
4794 if (importsController()) {
4795 // If this document is an HTML import, grab a reference to it's master d ocument's Content
4796 // Security Policy. We don't call 'initContentSecurityPolicy' in this ca se, as we can't
4797 // rebind the master document's policy object: its ExecutionContext need s to remain tied
4798 // to the master document.
4799 setContentSecurityPolicy(importsController()->master()->contentSecurityP olicy());
4800 } else {
4801 initContentSecurityPolicy();
4802 }
4801 4803
4802 if (Settings* settings = initializer.settings()) { 4804 if (Settings* settings = initializer.settings()) {
4803 if (!settings->webSecurityEnabled()) { 4805 if (!settings->webSecurityEnabled()) {
4804 // Web security is turned off. We should let this document access ev ery other document. This is used primary by testing 4806 // Web security is turned off. We should let this document access ev ery other document. This is used primary by testing
4805 // harnesses for web sites. 4807 // harnesses for web sites.
4806 securityOrigin()->grantUniversalAccess(); 4808 securityOrigin()->grantUniversalAccess();
4807 } else if (securityOrigin()->isLocal()) { 4809 } else if (securityOrigin()->isLocal()) {
4808 if (settings->allowUniversalAccessFromFileURLs()) { 4810 if (settings->allowUniversalAccessFromFileURLs()) {
4809 // Some clients want local URLs to have universal access, but th at setting is dangerous for other clients. 4811 // Some clients want local URLs to have universal access, but th at setting is dangerous for other clients.
4810 securityOrigin()->grantUniversalAccess(); 4812 securityOrigin()->grantUniversalAccess();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4842 securityOrigin()->grantLoadLocalResources(); 4844 securityOrigin()->grantLoadLocalResources();
4843 return; 4845 return;
4844 } 4846 }
4845 4847
4846 m_cookieURL = initializer.owner()->cookieURL(); 4848 m_cookieURL = initializer.owner()->cookieURL();
4847 // We alias the SecurityOrigins to match Firefox, see Bug 15313 4849 // We alias the SecurityOrigins to match Firefox, see Bug 15313
4848 // https://bugs.webkit.org/show_bug.cgi?id=15313 4850 // https://bugs.webkit.org/show_bug.cgi?id=15313
4849 setSecurityOrigin(initializer.owner()->securityOrigin()); 4851 setSecurityOrigin(initializer.owner()->securityOrigin());
4850 } 4852 }
4851 4853
4852 void Document::initContentSecurityPolicy(const ContentSecurityPolicyResponseHead ers& headers) 4854 void Document::initContentSecurityPolicy(PassRefPtr<ContentSecurityPolicy> csp)
4853 { 4855 {
4856 setContentSecurityPolicy(csp ? csp : ContentSecurityPolicy::create());
4854 if (m_frame && m_frame->tree().parent() && m_frame->tree().parent()->isLocal Frame() && (shouldInheritSecurityOriginFromOwner(m_url) || isPluginDocument())) 4857 if (m_frame && m_frame->tree().parent() && m_frame->tree().parent()->isLocal Frame() && (shouldInheritSecurityOriginFromOwner(m_url) || isPluginDocument()))
4855 contentSecurityPolicy()->copyStateFrom(toLocalFrame(m_frame->tree().pare nt())->document()->contentSecurityPolicy()); 4858 contentSecurityPolicy()->copyStateFrom(toLocalFrame(m_frame->tree().pare nt())->document()->contentSecurityPolicy());
4856 contentSecurityPolicy()->didReceiveHeaders(headers); 4859 if (transformSourceDocument())
4860 contentSecurityPolicy()->copyStateFrom(transformSourceDocument()->conten tSecurityPolicy());
4861 contentSecurityPolicy()->bindToExecutionContext(this);
4857 } 4862 }
4858 4863
4859 bool Document::allowInlineEventHandlers(Node* node, EventListener* listener, con st String& contextURL, const WTF::OrdinalNumber& contextLine) 4864 bool Document::allowInlineEventHandlers(Node* node, EventListener* listener, con st String& contextURL, const WTF::OrdinalNumber& contextLine)
4860 { 4865 {
4861 if (!contentSecurityPolicy()->allowInlineEventHandlers(contextURL, contextLi ne)) 4866 if (!contentSecurityPolicy()->allowInlineEventHandlers(contextURL, contextLi ne))
4862 return false; 4867 return false;
4863 4868
4864 // HTML says that inline script needs browsing context to create its executi on environment. 4869 // HTML says that inline script needs browsing context to create its executi on environment.
4865 // http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.ht ml#event-handler-attributes 4870 // http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.ht ml#event-handler-attributes
4866 // Also, if the listening node came from other document, which happens on co ntext-less event dispatching, 4871 // Also, if the listening node came from other document, which happens on co ntext-less event dispatching,
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
5826 using namespace blink; 5831 using namespace blink;
5827 void showLiveDocumentInstances() 5832 void showLiveDocumentInstances()
5828 { 5833 {
5829 WeakDocumentSet& set = liveDocumentSet(); 5834 WeakDocumentSet& set = liveDocumentSet();
5830 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5835 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5831 for (WeakDocumentSet::const_iterator it = set.begin(); it != set.end(); ++it ) { 5836 for (WeakDocumentSet::const_iterator it = set.begin(); it != set.end(); ++it ) {
5832 fprintf(stderr, "- Document %p URL: %s\n", *it, (*it)->url().string().ut f8().data()); 5837 fprintf(stderr, "- Document %p URL: %s\n", *it, (*it)->url().string().ut f8().data());
5833 } 5838 }
5834 } 5839 }
5835 #endif 5840 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/frame/csp/ContentSecurityPolicy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698