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