| 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 2785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2796 m_frame->localDOMWindow()->dispatchEvent(unloadEvent, m_frame->d
ocument()); | 2796 m_frame->localDOMWindow()->dispatchEvent(unloadEvent, m_frame->d
ocument()); |
| 2797 } | 2797 } |
| 2798 } | 2798 } |
| 2799 m_loadEventProgress = UnloadEventHandled; | 2799 m_loadEventProgress = UnloadEventHandled; |
| 2800 } | 2800 } |
| 2801 | 2801 |
| 2802 if (!m_frame) | 2802 if (!m_frame) |
| 2803 return; | 2803 return; |
| 2804 | 2804 |
| 2805 // Don't remove event listeners from a transitional empty document (see http
s://bugs.webkit.org/show_bug.cgi?id=28716 for more information). | 2805 // Don't remove event listeners from a transitional empty document (see http
s://bugs.webkit.org/show_bug.cgi?id=28716 for more information). |
| 2806 bool keepEventListeners = m_frame->loader().stateMachine()->isDisplayingInit
ialEmptyDocument() && m_frame->loader().provisionalDocumentLoader() | 2806 bool keepEventListeners = m_frame->loader().provisionalDocumentLoader() |
| 2807 && isSecureTransitionTo(m_frame->loader().provisionalDocumentLoader()->u
rl()); | 2807 && m_frame->shouldReuseDefaultView(m_frame->loader().provisionalDocument
Loader()->url()); |
| 2808 if (!keepEventListeners) | 2808 if (!keepEventListeners) |
| 2809 removeAllEventListenersRecursively(); | 2809 removeAllEventListenersRecursively(); |
| 2810 } | 2810 } |
| 2811 | 2811 |
| 2812 Document::PageDismissalType Document::pageDismissalEventBeingDispatched() const | 2812 Document::PageDismissalType Document::pageDismissalEventBeingDispatched() const |
| 2813 { | 2813 { |
| 2814 if (m_loadEventProgress == BeforeUnloadEventInProgress) | 2814 if (m_loadEventProgress == BeforeUnloadEventInProgress) |
| 2815 return BeforeUnloadDismissal; | 2815 return BeforeUnloadDismissal; |
| 2816 if (m_loadEventProgress == PageHideInProgress) | 2816 if (m_loadEventProgress == PageHideInProgress) |
| 2817 return PageHideDismissal; | 2817 return PageHideDismissal; |
| (...skipping 2089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4907 | 4907 |
| 4908 m_useSecureKeyboardEntryWhenActive = usesSecureKeyboard; | 4908 m_useSecureKeyboardEntryWhenActive = usesSecureKeyboard; |
| 4909 m_frame->selection().updateSecureKeyboardEntryIfActive(); | 4909 m_frame->selection().updateSecureKeyboardEntryIfActive(); |
| 4910 } | 4910 } |
| 4911 | 4911 |
| 4912 bool Document::useSecureKeyboardEntryWhenActive() const | 4912 bool Document::useSecureKeyboardEntryWhenActive() const |
| 4913 { | 4913 { |
| 4914 return m_useSecureKeyboardEntryWhenActive; | 4914 return m_useSecureKeyboardEntryWhenActive; |
| 4915 } | 4915 } |
| 4916 | 4916 |
| 4917 void Document::initSecurityContext() | |
| 4918 { | |
| 4919 initSecurityContext(DocumentInit(m_url, m_frame, contextDocument(), m_import
sController)); | |
| 4920 } | |
| 4921 | |
| 4922 void Document::initSecurityContext(const DocumentInit& initializer) | 4917 void Document::initSecurityContext(const DocumentInit& initializer) |
| 4923 { | 4918 { |
| 4924 if (haveInitializedSecurityOrigin()) { | 4919 ASSERT(!securityOrigin()); |
| 4925 ASSERT(securityOrigin()); | |
| 4926 return; | |
| 4927 } | |
| 4928 | 4920 |
| 4929 if (initializer.isHostedInReservedIPRange()) | 4921 if (initializer.isHostedInReservedIPRange()) |
| 4930 setHostedInReservedIPRange(); | 4922 setHostedInReservedIPRange(); |
| 4931 | 4923 |
| 4932 if (!initializer.hasSecurityContext()) { | 4924 if (!initializer.hasSecurityContext()) { |
| 4933 // No source for a security context. | 4925 // No source for a security context. |
| 4934 // This can occur via document.implementation.createDocument(). | 4926 // This can occur via document.implementation.createDocument(). |
| 4935 m_cookieURL = KURL(ParsedURLString, emptyString()); | 4927 m_cookieURL = KURL(ParsedURLString, emptyString()); |
| 4936 setSecurityOrigin(SecurityOrigin::createUnique()); | 4928 setSecurityOrigin(SecurityOrigin::createUnique()); |
| 4937 initContentSecurityPolicy(); | 4929 initContentSecurityPolicy(); |
| 4938 return; | 4930 return; |
| 4939 } | 4931 } |
| 4940 | 4932 |
| 4941 // In the common case, create the security context from the currently | 4933 // In the common case, create the security context from the currently |
| 4942 // loading URL with a fresh content security policy. | 4934 // loading URL with a fresh content security policy. |
| 4943 m_cookieURL = m_url; | |
| 4944 enforceSandboxFlags(initializer.sandboxFlags()); | 4935 enforceSandboxFlags(initializer.sandboxFlags()); |
| 4945 if (initializer.shouldEnforceStrictMixedContentChecking()) | 4936 if (initializer.shouldEnforceStrictMixedContentChecking()) |
| 4946 enforceStrictMixedContentChecking(); | 4937 enforceStrictMixedContentChecking(); |
| 4947 setInsecureRequestsPolicy(initializer.insecureRequestsPolicy()); | 4938 setInsecureRequestsPolicy(initializer.insecureRequestsPolicy()); |
| 4948 if (initializer.insecureNavigationsToUpgrade()) { | 4939 if (initializer.insecureNavigationsToUpgrade()) { |
| 4949 for (auto toUpgrade : *initializer.insecureNavigationsToUpgrade()) | 4940 for (auto toUpgrade : *initializer.insecureNavigationsToUpgrade()) |
| 4950 addInsecureNavigationUpgrade(toUpgrade); | 4941 addInsecureNavigationUpgrade(toUpgrade); |
| 4951 } | 4942 } |
| 4952 setSecurityOrigin(isSandboxed(SandboxOrigin) ? SecurityOrigin::createUnique(
) : SecurityOrigin::create(m_url)); | 4943 |
| 4944 if (isSandboxed(SandboxOrigin)) { |
| 4945 m_cookieURL = m_url; |
| 4946 setSecurityOrigin(SecurityOrigin::createUnique()); |
| 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() && initializer.owner()->securityOrigin()->canLoa
dLocalResources()) |
| 4952 securityOrigin()->grantLoadLocalResources(); |
| 4953 } else if (initializer.owner()) { |
| 4954 m_cookieURL = initializer.owner()->cookieURL(); |
| 4955 // We alias the SecurityOrigins to match Firefox, see Bug 15313 |
| 4956 // https://bugs.webkit.org/show_bug.cgi?id=15313 |
| 4957 setSecurityOrigin(initializer.owner()->securityOrigin()); |
| 4958 } else { |
| 4959 m_cookieURL = m_url; |
| 4960 setSecurityOrigin(SecurityOrigin::create(m_url)); |
| 4961 } |
| 4953 | 4962 |
| 4954 if (importsController()) { | 4963 if (importsController()) { |
| 4955 // If this document is an HTML import, grab a reference to it's master d
ocument's Content | 4964 // If this document is an HTML import, grab a reference to it's master d
ocument's Content |
| 4956 // Security Policy. We don't call 'initContentSecurityPolicy' in this ca
se, as we can't | 4965 // Security Policy. We don't call 'initContentSecurityPolicy' in this ca
se, as we can't |
| 4957 // rebind the master document's policy object: its ExecutionContext need
s to remain tied | 4966 // rebind the master document's policy object: its ExecutionContext need
s to remain tied |
| 4958 // to the master document. | 4967 // to the master document. |
| 4959 setContentSecurityPolicy(importsController()->master()->contentSecurityP
olicy()); | 4968 setContentSecurityPolicy(importsController()->master()->contentSecurityP
olicy()); |
| 4960 } else { | 4969 } else { |
| 4961 initContentSecurityPolicy(); | 4970 initContentSecurityPolicy(); |
| 4962 } | 4971 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4974 // Some clients do not want local URLs to have access to other l
ocal URLs. | 4983 // Some clients do not want local URLs to have access to other l
ocal URLs. |
| 4975 securityOrigin()->blockLocalAccessFromLocalOrigin(); | 4984 securityOrigin()->blockLocalAccessFromLocalOrigin(); |
| 4976 } | 4985 } |
| 4977 } | 4986 } |
| 4978 } | 4987 } |
| 4979 | 4988 |
| 4980 if (initializer.shouldTreatURLAsSrcdocDocument()) { | 4989 if (initializer.shouldTreatURLAsSrcdocDocument()) { |
| 4981 m_isSrcdocDocument = true; | 4990 m_isSrcdocDocument = true; |
| 4982 setBaseURLOverride(initializer.parentBaseURL()); | 4991 setBaseURLOverride(initializer.parentBaseURL()); |
| 4983 } | 4992 } |
| 4984 | |
| 4985 if (!shouldInheritSecurityOriginFromOwner(m_url)) | |
| 4986 return; | |
| 4987 | |
| 4988 // If we do not obtain a meaningful origin from the URL, then we try to | |
| 4989 // find one via the frame hierarchy. | |
| 4990 | |
| 4991 if (!initializer.owner()) { | |
| 4992 didFailToInitializeSecurityOrigin(); | |
| 4993 return; | |
| 4994 } | |
| 4995 | |
| 4996 if (isSandboxed(SandboxOrigin)) { | |
| 4997 // If we're supposed to inherit our security origin from our owner, | |
| 4998 // but we're also sandboxed, the only thing we inherit is the ability | |
| 4999 // to load local resources. This lets about:blank iframes in file:// | |
| 5000 // URL documents load images and other resources from the file system. | |
| 5001 if (initializer.owner()->securityOrigin()->canLoadLocalResources()) | |
| 5002 securityOrigin()->grantLoadLocalResources(); | |
| 5003 return; | |
| 5004 } | |
| 5005 | |
| 5006 m_cookieURL = initializer.owner()->cookieURL(); | |
| 5007 // We alias the SecurityOrigins to match Firefox, see Bug 15313 | |
| 5008 // https://bugs.webkit.org/show_bug.cgi?id=15313 | |
| 5009 setSecurityOrigin(initializer.owner()->securityOrigin()); | |
| 5010 } | 4993 } |
| 5011 | 4994 |
| 5012 void Document::initContentSecurityPolicy(PassRefPtrWillBeRawPtr<ContentSecurityP
olicy> csp) | 4995 void Document::initContentSecurityPolicy(PassRefPtrWillBeRawPtr<ContentSecurityP
olicy> csp) |
| 5013 { | 4996 { |
| 5014 setContentSecurityPolicy(csp ? csp : ContentSecurityPolicy::create()); | 4997 setContentSecurityPolicy(csp ? csp : ContentSecurityPolicy::create()); |
| 5015 if (m_frame && m_frame->tree().parent() && m_frame->tree().parent()->isLocal
Frame()) { | 4998 if (m_frame && m_frame->tree().parent() && m_frame->tree().parent()->isLocal
Frame()) { |
| 5016 ContentSecurityPolicy* parentCSP = toLocalFrame(m_frame->tree().parent()
)->document()->contentSecurityPolicy(); | 4999 ContentSecurityPolicy* parentCSP = toLocalFrame(m_frame->tree().parent()
)->document()->contentSecurityPolicy(); |
| 5017 if (shouldInheritSecurityOriginFromOwner(m_url)) { | 5000 if (shouldInheritSecurityOriginFromOwner(m_url)) { |
| 5018 contentSecurityPolicy()->copyStateFrom(parentCSP); | 5001 contentSecurityPolicy()->copyStateFrom(parentCSP); |
| 5019 } else if (isPluginDocument()) { | 5002 } else if (isPluginDocument()) { |
| 5020 // Per CSP2, plugin-types for plugin documents in nested browsing | 5003 // Per CSP2, plugin-types for plugin documents in nested browsing |
| 5021 // contexts gets inherited from the parent. | 5004 // contexts gets inherited from the parent. |
| 5022 contentSecurityPolicy()->copyPluginTypesFrom(parentCSP); | 5005 contentSecurityPolicy()->copyPluginTypesFrom(parentCSP); |
| 5023 } | 5006 } |
| 5024 } | 5007 } |
| 5025 contentSecurityPolicy()->bindToExecutionContext(this); | 5008 contentSecurityPolicy()->bindToExecutionContext(this); |
| 5026 } | 5009 } |
| 5027 | 5010 |
| 5011 bool Document::isSecureTransitionTo(const KURL& url) const |
| 5012 { |
| 5013 RefPtr<SecurityOrigin> other = SecurityOrigin::create(url); |
| 5014 return securityOrigin()->canAccess(other.get()); |
| 5015 } |
| 5016 |
| 5028 bool Document::allowInlineEventHandlers(Node* node, EventListener* listener, con
st String& contextURL, const WTF::OrdinalNumber& contextLine) | 5017 bool Document::allowInlineEventHandlers(Node* node, EventListener* listener, con
st String& contextURL, const WTF::OrdinalNumber& contextLine) |
| 5029 { | 5018 { |
| 5030 bool allowedByHash = contentSecurityPolicy()->experimentalFeaturesEnabled()
&& contentSecurityPolicy()->allowScriptWithHash(listener->code()); | 5019 bool allowedByHash = contentSecurityPolicy()->experimentalFeaturesEnabled()
&& contentSecurityPolicy()->allowScriptWithHash(listener->code()); |
| 5031 if (!ContentSecurityPolicy::shouldBypassMainWorld(this) && !allowedByHash &&
!contentSecurityPolicy()->allowInlineEventHandlers(contextURL, contextLine)) | 5020 if (!ContentSecurityPolicy::shouldBypassMainWorld(this) && !allowedByHash &&
!contentSecurityPolicy()->allowInlineEventHandlers(contextURL, contextLine)) |
| 5032 return false; | 5021 return false; |
| 5033 | 5022 |
| 5034 // HTML says that inline script needs browsing context to create its executi
on environment. | 5023 // HTML says that inline script needs browsing context to create its executi
on environment. |
| 5035 // http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.ht
ml#event-handler-attributes | 5024 // http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.ht
ml#event-handler-attributes |
| 5036 // Also, if the listening node came from other document, which happens on co
ntext-less event dispatching, | 5025 // Also, if the listening node came from other document, which happens on co
ntext-less event dispatching, |
| 5037 // we also need to ask the owner document of the node. | 5026 // we also need to ask the owner document of the node. |
| (...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5994 #ifndef NDEBUG | 5983 #ifndef NDEBUG |
| 5995 using namespace blink; | 5984 using namespace blink; |
| 5996 void showLiveDocumentInstances() | 5985 void showLiveDocumentInstances() |
| 5997 { | 5986 { |
| 5998 Document::WeakDocumentSet& set = Document::liveDocumentSet(); | 5987 Document::WeakDocumentSet& set = Document::liveDocumentSet(); |
| 5999 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 5988 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
| 6000 for (Document* document : set) | 5989 for (Document* document : set) |
| 6001 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str
ing().utf8().data()); | 5990 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str
ing().utf8().data()); |
| 6002 } | 5991 } |
| 6003 #endif | 5992 #endif |
| OLD | NEW |