Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/Document.cpp |
| diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp |
| index 64f72e837e40d3a5cb3d7d72c4b4a0cc95adb60d..99815e73a6a81302a07d616952bde9ac0f2c158d 100644 |
| --- a/third_party/WebKit/Source/core/dom/Document.cpp |
| +++ b/third_party/WebKit/Source/core/dom/Document.cpp |
| @@ -2803,8 +2803,8 @@ void Document::dispatchUnloadEvents() |
| return; |
| // Don't remove event listeners from a transitional empty document (see https://bugs.webkit.org/show_bug.cgi?id=28716 for more information). |
| - bool keepEventListeners = m_frame->loader().stateMachine()->isDisplayingInitialEmptyDocument() && m_frame->loader().provisionalDocumentLoader() |
| - && isSecureTransitionTo(m_frame->loader().provisionalDocumentLoader()->url()); |
| + bool keepEventListeners = m_frame->loader().provisionalDocumentLoader() |
| + && m_frame->shouldReuseDefaultView(m_frame->loader().provisionalDocumentLoader()->url()); |
| if (!keepEventListeners) |
| removeAllEventListenersRecursively(); |
| } |
| @@ -4915,17 +4915,9 @@ bool Document::useSecureKeyboardEntryWhenActive() const |
| return m_useSecureKeyboardEntryWhenActive; |
| } |
| -void Document::initSecurityContext() |
| -{ |
| - initSecurityContext(DocumentInit(m_url, m_frame, contextDocument(), m_importsController)); |
| -} |
| - |
| void Document::initSecurityContext(const DocumentInit& initializer) |
| { |
| - if (haveInitializedSecurityOrigin()) { |
| - ASSERT(securityOrigin()); |
| - return; |
| - } |
| + 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
|
| if (initializer.isHostedInReservedIPRange()) |
| setHostedInReservedIPRange(); |
| @@ -4941,7 +4933,6 @@ void Document::initSecurityContext(const DocumentInit& initializer) |
| // In the common case, create the security context from the currently |
| // loading URL with a fresh content security policy. |
| - m_cookieURL = m_url; |
| enforceSandboxFlags(initializer.getSandboxFlags()); |
| if (initializer.shouldEnforceStrictMixedContentChecking()) |
| enforceStrictMixedContentChecking(); |
| @@ -4950,7 +4941,25 @@ void Document::initSecurityContext(const DocumentInit& initializer) |
| for (auto toUpgrade : *initializer.insecureNavigationsToUpgrade()) |
| addInsecureNavigationUpgrade(toUpgrade); |
| } |
| - setSecurityOrigin(isSandboxed(SandboxOrigin) ? SecurityOrigin::createUnique() : SecurityOrigin::create(m_url)); |
| + |
| + if (isSandboxed(SandboxOrigin)) { |
| + m_cookieURL = m_url; |
| + setSecurityOrigin(SecurityOrigin::createUnique()); |
| + // If we're supposed to inherit our security origin from our owner, |
| + // but we're also sandboxed, the only thing we inherit is the ability |
| + // to load local resources. This lets about:blank iframes in file:// |
| + // URL documents load images and other resources from the file system. |
| + if (initializer.owner() && initializer.owner()->securityOrigin()->canLoadLocalResources()) |
| + securityOrigin()->grantLoadLocalResources(); |
| + } else if (initializer.owner()) { |
| + m_cookieURL = initializer.owner()->cookieURL(); |
| + // We alias the SecurityOrigins to match Firefox, see Bug 15313 |
| + // https://bugs.webkit.org/show_bug.cgi?id=15313 |
| + setSecurityOrigin(initializer.owner()->securityOrigin()); |
| + } else { |
| + m_cookieURL = m_url; |
| + setSecurityOrigin(SecurityOrigin::create(m_url)); |
| + } |
| if (importsController()) { |
| // If this document is an HTML import, grab a reference to it's master document's Content |
| @@ -4982,32 +4991,6 @@ void Document::initSecurityContext(const DocumentInit& initializer) |
| m_isSrcdocDocument = true; |
| setBaseURLOverride(initializer.parentBaseURL()); |
| } |
| - |
| - if (!shouldInheritSecurityOriginFromOwner(m_url)) |
| - return; |
| - |
| - // If we do not obtain a meaningful origin from the URL, then we try to |
| - // find one via the frame hierarchy. |
| - |
| - if (!initializer.owner()) { |
| - didFailToInitializeSecurityOrigin(); |
| - return; |
| - } |
| - |
| - if (isSandboxed(SandboxOrigin)) { |
| - // If we're supposed to inherit our security origin from our owner, |
| - // but we're also sandboxed, the only thing we inherit is the ability |
| - // to load local resources. This lets about:blank iframes in file:// |
| - // URL documents load images and other resources from the file system. |
| - if (initializer.owner()->securityOrigin()->canLoadLocalResources()) |
| - securityOrigin()->grantLoadLocalResources(); |
| - return; |
| - } |
| - |
| - m_cookieURL = initializer.owner()->cookieURL(); |
| - // We alias the SecurityOrigins to match Firefox, see Bug 15313 |
| - // https://bugs.webkit.org/show_bug.cgi?id=15313 |
| - setSecurityOrigin(initializer.owner()->securityOrigin()); |
| } |
| void Document::initContentSecurityPolicy(PassRefPtrWillBeRawPtr<ContentSecurityPolicy> csp) |
| @@ -5026,6 +5009,12 @@ void Document::initContentSecurityPolicy(PassRefPtrWillBeRawPtr<ContentSecurityP |
| contentSecurityPolicy()->bindToExecutionContext(this); |
| } |
| +bool Document::isSecureTransitionTo(const KURL& url) const |
| +{ |
| + RefPtr<SecurityOrigin> other = SecurityOrigin::create(url); |
| + return securityOrigin()->canAccess(other.get()); |
| +} |
| + |
| bool Document::allowInlineEventHandlers(Node* node, EventListener* listener, const String& contextURL, const WTF::OrdinalNumber& contextLine) |
| { |
| bool allowedByHash = contentSecurityPolicy()->experimentalFeaturesEnabled() && contentSecurityPolicy()->allowScriptWithHash(listener->code()); |