OLD | NEW |
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 2779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2790 m_frame->localDOMWindow()->dispatchEvent(unloadEvent, m_frame->d
ocument()); | 2790 m_frame->localDOMWindow()->dispatchEvent(unloadEvent, m_frame->d
ocument()); |
2791 } | 2791 } |
2792 } | 2792 } |
2793 m_loadEventProgress = UnloadEventHandled; | 2793 m_loadEventProgress = UnloadEventHandled; |
2794 } | 2794 } |
2795 | 2795 |
2796 if (!m_frame) | 2796 if (!m_frame) |
2797 return; | 2797 return; |
2798 | 2798 |
2799 // Don't remove event listeners from a transitional empty document (see http
s://bugs.webkit.org/show_bug.cgi?id=28716 for more information). | 2799 // Don't remove event listeners from a transitional empty document (see http
s://bugs.webkit.org/show_bug.cgi?id=28716 for more information). |
2800 bool keepEventListeners = m_frame->loader().stateMachine()->isDisplayingInit
ialEmptyDocument() && m_frame->loader().provisionalDocumentLoader() | 2800 bool keepEventListeners = m_frame->loader().provisionalDocumentLoader() |
2801 && isSecureTransitionTo(m_frame->loader().provisionalDocumentLoader()->u
rl()); | 2801 && m_frame->shouldReuseDefaultView(m_frame->loader().provisionalDocument
Loader()->url()); |
2802 if (!keepEventListeners) | 2802 if (!keepEventListeners) |
2803 removeAllEventListenersRecursively(); | 2803 removeAllEventListenersRecursively(); |
2804 } | 2804 } |
2805 | 2805 |
2806 Document::PageDismissalType Document::pageDismissalEventBeingDispatched() const | 2806 Document::PageDismissalType Document::pageDismissalEventBeingDispatched() const |
2807 { | 2807 { |
2808 if (m_loadEventProgress == BeforeUnloadEventInProgress) | 2808 if (m_loadEventProgress == BeforeUnloadEventInProgress) |
2809 return BeforeUnloadDismissal; | 2809 return BeforeUnloadDismissal; |
2810 if (m_loadEventProgress == PageHideInProgress) | 2810 if (m_loadEventProgress == PageHideInProgress) |
2811 return PageHideDismissal; | 2811 return PageHideDismissal; |
(...skipping 2045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4857 | 4857 |
4858 m_useSecureKeyboardEntryWhenActive = usesSecureKeyboard; | 4858 m_useSecureKeyboardEntryWhenActive = usesSecureKeyboard; |
4859 m_frame->selection().updateSecureKeyboardEntryIfActive(); | 4859 m_frame->selection().updateSecureKeyboardEntryIfActive(); |
4860 } | 4860 } |
4861 | 4861 |
4862 bool Document::useSecureKeyboardEntryWhenActive() const | 4862 bool Document::useSecureKeyboardEntryWhenActive() const |
4863 { | 4863 { |
4864 return m_useSecureKeyboardEntryWhenActive; | 4864 return m_useSecureKeyboardEntryWhenActive; |
4865 } | 4865 } |
4866 | 4866 |
4867 void Document::initSecurityContext() | |
4868 { | |
4869 initSecurityContext(DocumentInit(m_url, m_frame, contextDocument(), m_import
sController)); | |
4870 } | |
4871 | |
4872 void Document::initSecurityContext(const DocumentInit& initializer) | 4867 void Document::initSecurityContext(const DocumentInit& initializer) |
4873 { | 4868 { |
4874 if (haveInitializedSecurityOrigin()) { | 4869 ASSERT(!securityOrigin()); |
4875 ASSERT(securityOrigin()); | |
4876 return; | |
4877 } | |
4878 | 4870 |
4879 if (initializer.isHostedInReservedIPRange()) | 4871 if (initializer.isHostedInReservedIPRange()) |
4880 setHostedInReservedIPRange(); | 4872 setHostedInReservedIPRange(); |
4881 | 4873 |
4882 if (!initializer.hasSecurityContext()) { | 4874 if (!initializer.hasSecurityContext()) { |
4883 // No source for a security context. | 4875 // No source for a security context. |
4884 // This can occur via document.implementation.createDocument(). | 4876 // This can occur via document.implementation.createDocument(). |
4885 m_cookieURL = KURL(ParsedURLString, emptyString()); | 4877 m_cookieURL = KURL(ParsedURLString, emptyString()); |
4886 setSecurityOrigin(SecurityOrigin::createUnique()); | 4878 setSecurityOrigin(SecurityOrigin::createUnique()); |
4887 initContentSecurityPolicy(); | 4879 initContentSecurityPolicy(); |
4888 return; | 4880 return; |
4889 } | 4881 } |
4890 | 4882 |
4891 // In the common case, create the security context from the currently | 4883 // In the common case, create the security context from the currently |
4892 // loading URL with a fresh content security policy. | 4884 // loading URL with a fresh content security policy. |
4893 m_cookieURL = m_url; | |
4894 enforceSandboxFlags(initializer.sandboxFlags()); | 4885 enforceSandboxFlags(initializer.sandboxFlags()); |
4895 if (initializer.shouldEnforceStrictMixedContentChecking()) | 4886 if (initializer.shouldEnforceStrictMixedContentChecking()) |
4896 enforceStrictMixedContentChecking(); | 4887 enforceStrictMixedContentChecking(); |
4897 setInsecureRequestsPolicy(initializer.insecureRequestsPolicy()); | 4888 setInsecureRequestsPolicy(initializer.insecureRequestsPolicy()); |
4898 if (initializer.insecureNavigationsToUpgrade()) { | 4889 if (initializer.insecureNavigationsToUpgrade()) { |
4899 for (auto toUpgrade : *initializer.insecureNavigationsToUpgrade()) | 4890 for (auto toUpgrade : *initializer.insecureNavigationsToUpgrade()) |
4900 addInsecureNavigationUpgrade(toUpgrade); | 4891 addInsecureNavigationUpgrade(toUpgrade); |
4901 } | 4892 } |
4902 setSecurityOrigin(isSandboxed(SandboxOrigin) ? SecurityOrigin::createUnique(
) : SecurityOrigin::create(m_url)); | 4893 |
| 4894 if (isSandboxed(SandboxOrigin)) { |
| 4895 m_cookieURL = m_url; |
| 4896 setSecurityOrigin(SecurityOrigin::createUnique()); |
| 4897 // If we're supposed to inherit our security origin from our owner, |
| 4898 // but we're also sandboxed, the only thing we inherit is the ability |
| 4899 // to load local resources. This lets about:blank iframes in file:// |
| 4900 // URL documents load images and other resources from the file system. |
| 4901 if (initializer.owner() && initializer.owner()->securityOrigin()->canLoa
dLocalResources()) |
| 4902 securityOrigin()->grantLoadLocalResources(); |
| 4903 } else if (initializer.owner()) { |
| 4904 m_cookieURL = initializer.owner()->cookieURL(); |
| 4905 // We alias the SecurityOrigins to match Firefox, see Bug 15313 |
| 4906 // https://bugs.webkit.org/show_bug.cgi?id=15313 |
| 4907 setSecurityOrigin(initializer.owner()->securityOrigin()); |
| 4908 } else { |
| 4909 m_cookieURL = m_url; |
| 4910 setSecurityOrigin(SecurityOrigin::create(m_url)); |
| 4911 } |
4903 | 4912 |
4904 if (importsController()) { | 4913 if (importsController()) { |
4905 // If this document is an HTML import, grab a reference to it's master d
ocument's Content | 4914 // If this document is an HTML import, grab a reference to it's master d
ocument's Content |
4906 // Security Policy. We don't call 'initContentSecurityPolicy' in this ca
se, as we can't | 4915 // Security Policy. We don't call 'initContentSecurityPolicy' in this ca
se, as we can't |
4907 // rebind the master document's policy object: its ExecutionContext need
s to remain tied | 4916 // rebind the master document's policy object: its ExecutionContext need
s to remain tied |
4908 // to the master document. | 4917 // to the master document. |
4909 setContentSecurityPolicy(importsController()->master()->contentSecurityP
olicy()); | 4918 setContentSecurityPolicy(importsController()->master()->contentSecurityP
olicy()); |
4910 } else { | 4919 } else { |
4911 initContentSecurityPolicy(); | 4920 initContentSecurityPolicy(); |
4912 } | 4921 } |
(...skipping 11 matching lines...) Expand all Loading... |
4924 // Some clients do not want local URLs to have access to other l
ocal URLs. | 4933 // Some clients do not want local URLs to have access to other l
ocal URLs. |
4925 securityOrigin()->blockLocalAccessFromLocalOrigin(); | 4934 securityOrigin()->blockLocalAccessFromLocalOrigin(); |
4926 } | 4935 } |
4927 } | 4936 } |
4928 } | 4937 } |
4929 | 4938 |
4930 if (initializer.shouldTreatURLAsSrcdocDocument()) { | 4939 if (initializer.shouldTreatURLAsSrcdocDocument()) { |
4931 m_isSrcdocDocument = true; | 4940 m_isSrcdocDocument = true; |
4932 setBaseURLOverride(initializer.parentBaseURL()); | 4941 setBaseURLOverride(initializer.parentBaseURL()); |
4933 } | 4942 } |
4934 | |
4935 if (!shouldInheritSecurityOriginFromOwner(m_url)) | |
4936 return; | |
4937 | |
4938 // If we do not obtain a meaningful origin from the URL, then we try to | |
4939 // find one via the frame hierarchy. | |
4940 | |
4941 if (!initializer.owner()) { | |
4942 didFailToInitializeSecurityOrigin(); | |
4943 return; | |
4944 } | |
4945 | |
4946 if (isSandboxed(SandboxOrigin)) { | |
4947 // If we're supposed to inherit our security origin from our owner, | |
4948 // but we're also sandboxed, the only thing we inherit is the ability | |
4949 // to load local resources. This lets about:blank iframes in file:// | |
4950 // URL documents load images and other resources from the file system. | |
4951 if (initializer.owner()->securityOrigin()->canLoadLocalResources()) | |
4952 securityOrigin()->grantLoadLocalResources(); | |
4953 return; | |
4954 } | |
4955 | |
4956 m_cookieURL = initializer.owner()->cookieURL(); | |
4957 // We alias the SecurityOrigins to match Firefox, see Bug 15313 | |
4958 // https://bugs.webkit.org/show_bug.cgi?id=15313 | |
4959 setSecurityOrigin(initializer.owner()->securityOrigin()); | |
4960 } | 4943 } |
4961 | 4944 |
4962 void Document::initContentSecurityPolicy(PassRefPtrWillBeRawPtr<ContentSecurityP
olicy> csp) | 4945 void Document::initContentSecurityPolicy(PassRefPtrWillBeRawPtr<ContentSecurityP
olicy> csp) |
4963 { | 4946 { |
4964 setContentSecurityPolicy(csp ? csp : ContentSecurityPolicy::create()); | 4947 setContentSecurityPolicy(csp ? csp : ContentSecurityPolicy::create()); |
4965 if (m_frame && m_frame->tree().parent() && m_frame->tree().parent()->isLocal
Frame()) { | 4948 if (m_frame && m_frame->tree().parent() && m_frame->tree().parent()->isLocal
Frame()) { |
4966 ContentSecurityPolicy* parentCSP = toLocalFrame(m_frame->tree().parent()
)->document()->contentSecurityPolicy(); | 4949 ContentSecurityPolicy* parentCSP = toLocalFrame(m_frame->tree().parent()
)->document()->contentSecurityPolicy(); |
4967 if (shouldInheritSecurityOriginFromOwner(m_url)) { | 4950 if (shouldInheritSecurityOriginFromOwner(m_url)) { |
4968 contentSecurityPolicy()->copyStateFrom(parentCSP); | 4951 contentSecurityPolicy()->copyStateFrom(parentCSP); |
4969 } else if (isPluginDocument()) { | 4952 } else if (isPluginDocument()) { |
4970 // Per CSP2, plugin-types for plugin documents in nested browsing | 4953 // Per CSP2, plugin-types for plugin documents in nested browsing |
4971 // contexts gets inherited from the parent. | 4954 // contexts gets inherited from the parent. |
4972 contentSecurityPolicy()->copyPluginTypesFrom(parentCSP); | 4955 contentSecurityPolicy()->copyPluginTypesFrom(parentCSP); |
4973 } | 4956 } |
4974 } | 4957 } |
4975 contentSecurityPolicy()->bindToExecutionContext(this); | 4958 contentSecurityPolicy()->bindToExecutionContext(this); |
4976 } | 4959 } |
4977 | 4960 |
| 4961 bool Document::isSecureTransitionTo(const KURL& url) const |
| 4962 { |
| 4963 RefPtr<SecurityOrigin> other = SecurityOrigin::create(url); |
| 4964 return securityOrigin()->canAccess(other.get()); |
| 4965 } |
| 4966 |
4978 bool Document::allowInlineEventHandlers(Node* node, EventListener* listener, con
st String& contextURL, const WTF::OrdinalNumber& contextLine) | 4967 bool Document::allowInlineEventHandlers(Node* node, EventListener* listener, con
st String& contextURL, const WTF::OrdinalNumber& contextLine) |
4979 { | 4968 { |
4980 bool allowedByHash = contentSecurityPolicy()->experimentalFeaturesEnabled()
&& contentSecurityPolicy()->allowScriptWithHash(listener->code()); | 4969 bool allowedByHash = contentSecurityPolicy()->experimentalFeaturesEnabled()
&& contentSecurityPolicy()->allowScriptWithHash(listener->code()); |
4981 if (!ContentSecurityPolicy::shouldBypassMainWorld(this) && !allowedByHash &&
!contentSecurityPolicy()->allowInlineEventHandlers(contextURL, contextLine)) | 4970 if (!ContentSecurityPolicy::shouldBypassMainWorld(this) && !allowedByHash &&
!contentSecurityPolicy()->allowInlineEventHandlers(contextURL, contextLine)) |
4982 return false; | 4971 return false; |
4983 | 4972 |
4984 // HTML says that inline script needs browsing context to create its executi
on environment. | 4973 // HTML says that inline script needs browsing context to create its executi
on environment. |
4985 // http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.ht
ml#event-handler-attributes | 4974 // http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.ht
ml#event-handler-attributes |
4986 // Also, if the listening node came from other document, which happens on co
ntext-less event dispatching, | 4975 // Also, if the listening node came from other document, which happens on co
ntext-less event dispatching, |
4987 // we also need to ask the owner document of the node. | 4976 // we also need to ask the owner document of the node. |
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5948 #ifndef NDEBUG | 5937 #ifndef NDEBUG |
5949 using namespace blink; | 5938 using namespace blink; |
5950 void showLiveDocumentInstances() | 5939 void showLiveDocumentInstances() |
5951 { | 5940 { |
5952 Document::WeakDocumentSet& set = Document::liveDocumentSet(); | 5941 Document::WeakDocumentSet& set = Document::liveDocumentSet(); |
5953 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 5942 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
5954 for (Document* document : set) | 5943 for (Document* document : set) |
5955 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str
ing().utf8().data()); | 5944 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str
ing().utf8().data()); |
5956 } | 5945 } |
5957 #endif | 5946 #endif |
OLD | NEW |