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

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: Rebase. 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
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 4775 matching lines...) Expand 10 before | Expand all | Expand 10 after
4786 bool Document::useSecureKeyboardEntryWhenActive() const 4786 bool Document::useSecureKeyboardEntryWhenActive() const
4787 { 4787 {
4788 return m_useSecureKeyboardEntryWhenActive; 4788 return m_useSecureKeyboardEntryWhenActive;
4789 } 4789 }
4790 4790
4791 void Document::initSecurityContext() 4791 void Document::initSecurityContext()
4792 { 4792 {
4793 initSecurityContext(DocumentInit(m_url, m_frame, contextDocument(), m_import sController)); 4793 initSecurityContext(DocumentInit(m_url, m_frame, contextDocument(), m_import sController));
4794 } 4794 }
4795 4795
4796 static PassRefPtr<ContentSecurityPolicy> contentSecurityPolicyFor(Document* docu ment)
4797 {
4798 if (document->importsController())
4799 return document->importsController()->master()->contentSecurityPolicy();
4800 return ContentSecurityPolicy::create(document);
4801 }
4802
4803 void Document::initSecurityContext(const DocumentInit& initializer) 4796 void Document::initSecurityContext(const DocumentInit& initializer)
4804 { 4797 {
4805 if (haveInitializedSecurityOrigin()) { 4798 if (haveInitializedSecurityOrigin()) {
4806 ASSERT(securityOrigin()); 4799 ASSERT(securityOrigin());
4807 return; 4800 return;
4808 } 4801 }
4809 4802
4810 if (!initializer.hasSecurityContext()) { 4803 if (!initializer.hasSecurityContext()) {
4811 // No source for a security context. 4804 // No source for a security context.
4812 // This can occur via document.implementation.createDocument(). 4805 // This can occur via document.implementation.createDocument().
4813 m_cookieURL = KURL(ParsedURLString, emptyString()); 4806 m_cookieURL = KURL(ParsedURLString, emptyString());
4814 setSecurityOrigin(SecurityOrigin::createUnique()); 4807 setSecurityOrigin(SecurityOrigin::createUnique());
4815 setContentSecurityPolicy(ContentSecurityPolicy::create(this)); 4808 initContentSecurityPolicy();
4816 return; 4809 return;
4817 } 4810 }
4818 4811
4819 // In the common case, create the security context from the currently 4812 // In the common case, create the security context from the currently
4820 // loading URL with a fresh content security policy. 4813 // loading URL with a fresh content security policy.
4821 m_cookieURL = m_url; 4814 m_cookieURL = m_url;
4822 enforceSandboxFlags(initializer.sandboxFlags()); 4815 enforceSandboxFlags(initializer.sandboxFlags());
4823 setSecurityOrigin(isSandboxed(SandboxOrigin) ? SecurityOrigin::createUnique( ) : SecurityOrigin::create(m_url)); 4816 setSecurityOrigin(isSandboxed(SandboxOrigin) ? SecurityOrigin::createUnique( ) : SecurityOrigin::create(m_url));
4824 setContentSecurityPolicy(contentSecurityPolicyFor(this)); 4817
4818 // If this document is an HTML import, grab a reference to it's master docum ent's Content Security Policy.
4819 // Otherwise, the CSP object will be initialized in 'initContentSecurityPoli cy'.
sof 2014/09/11 07:44:04 Where do you ensure that it is being called if not
Mike West 2014/09/11 08:29:13 Hrm. What would you like to see? `initContentSecur
4820 if (importsController())
4821 setContentSecurityPolicy(importsController()->master()->contentSecurityP olicy());
4825 4822
4826 if (Settings* settings = initializer.settings()) { 4823 if (Settings* settings = initializer.settings()) {
4827 if (!settings->webSecurityEnabled()) { 4824 if (!settings->webSecurityEnabled()) {
4828 // Web security is turned off. We should let this document access ev ery other document. This is used primary by testing 4825 // Web security is turned off. We should let this document access ev ery other document. This is used primary by testing
4829 // harnesses for web sites. 4826 // harnesses for web sites.
4830 securityOrigin()->grantUniversalAccess(); 4827 securityOrigin()->grantUniversalAccess();
4831 } else if (securityOrigin()->isLocal()) { 4828 } else if (securityOrigin()->isLocal()) {
4832 if (settings->allowUniversalAccessFromFileURLs()) { 4829 if (settings->allowUniversalAccessFromFileURLs()) {
4833 // Some clients want local URLs to have universal access, but th at setting is dangerous for other clients. 4830 // Some clients want local URLs to have universal access, but th at setting is dangerous for other clients.
4834 securityOrigin()->grantUniversalAccess(); 4831 securityOrigin()->grantUniversalAccess();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4866 securityOrigin()->grantLoadLocalResources(); 4863 securityOrigin()->grantLoadLocalResources();
4867 return; 4864 return;
4868 } 4865 }
4869 4866
4870 m_cookieURL = initializer.owner()->cookieURL(); 4867 m_cookieURL = initializer.owner()->cookieURL();
4871 // We alias the SecurityOrigins to match Firefox, see Bug 15313 4868 // We alias the SecurityOrigins to match Firefox, see Bug 15313
4872 // https://bugs.webkit.org/show_bug.cgi?id=15313 4869 // https://bugs.webkit.org/show_bug.cgi?id=15313
4873 setSecurityOrigin(initializer.owner()->securityOrigin()); 4870 setSecurityOrigin(initializer.owner()->securityOrigin());
4874 } 4871 }
4875 4872
4876 void Document::initContentSecurityPolicy(const ContentSecurityPolicyResponseHead ers& headers) 4873 void Document::initContentSecurityPolicy(PassRefPtr<ContentSecurityPolicy> csp)
4877 { 4874 {
4875 ASSERT(!contentSecurityPolicy() || !csp);
4876 setContentSecurityPolicy(csp ? csp : ContentSecurityPolicy::create());
4878 if (m_frame && m_frame->tree().parent() && m_frame->tree().parent()->isLocal Frame() && (shouldInheritSecurityOriginFromOwner(m_url) || isPluginDocument())) 4877 if (m_frame && m_frame->tree().parent() && m_frame->tree().parent()->isLocal Frame() && (shouldInheritSecurityOriginFromOwner(m_url) || isPluginDocument()))
4879 contentSecurityPolicy()->copyStateFrom(toLocalFrame(m_frame->tree().pare nt())->document()->contentSecurityPolicy()); 4878 contentSecurityPolicy()->copyStateFrom(toLocalFrame(m_frame->tree().pare nt())->document()->contentSecurityPolicy());
4880 contentSecurityPolicy()->didReceiveHeaders(headers); 4879 if (transformSourceDocument())
4880 contentSecurityPolicy()->copyStateFrom(transformSourceDocument()->conten tSecurityPolicy());
4881 contentSecurityPolicy()->bindToExecutionContext(this);
4881 } 4882 }
4882 4883
4883 bool Document::allowInlineEventHandlers(Node* node, EventListener* listener, con st String& contextURL, const WTF::OrdinalNumber& contextLine) 4884 bool Document::allowInlineEventHandlers(Node* node, EventListener* listener, con st String& contextURL, const WTF::OrdinalNumber& contextLine)
4884 { 4885 {
4885 if (!contentSecurityPolicy()->allowInlineEventHandlers(contextURL, contextLi ne)) 4886 if (!contentSecurityPolicy()->allowInlineEventHandlers(contextURL, contextLi ne))
4886 return false; 4887 return false;
4887 4888
4888 // HTML says that inline script needs browsing context to create its executi on environment. 4889 // HTML says that inline script needs browsing context to create its executi on environment.
4889 // http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.ht ml#event-handler-attributes 4890 // http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.ht ml#event-handler-attributes
4890 // Also, if the listening node came from other document, which happens on co ntext-less event dispatching, 4891 // 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
5850 using namespace blink; 5851 using namespace blink;
5851 void showLiveDocumentInstances() 5852 void showLiveDocumentInstances()
5852 { 5853 {
5853 WeakDocumentSet& set = liveDocumentSet(); 5854 WeakDocumentSet& set = liveDocumentSet();
5854 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5855 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5855 for (WeakDocumentSet::const_iterator it = set.begin(); it != set.end(); ++it ) { 5856 for (WeakDocumentSet::const_iterator it = set.begin(); it != set.end(); ++it ) {
5856 fprintf(stderr, "- Document %p URL: %s\n", *it, (*it)->url().string().ut f8().data()); 5857 fprintf(stderr, "- Document %p URL: %s\n", *it, (*it)->url().string().ut f8().data());
5857 } 5858 }
5858 } 5859 }
5859 #endif 5860 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698