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

Side by Side Diff: Source/core/dom/Document.cpp

Issue 33353003: Have Frame::tree() return a reference (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 2 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
« no previous file with comments | « Source/bindings/v8/custom/V8WindowCustom.cpp ('k') | Source/core/dom/DocumentInit.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 311 }
312 312
313 static bool canAccessAncestor(const SecurityOrigin* activeSecurityOrigin, Frame* targetFrame) 313 static bool canAccessAncestor(const SecurityOrigin* activeSecurityOrigin, Frame* targetFrame)
314 { 314 {
315 // targetFrame can be 0 when we're trying to navigate a top-level frame 315 // targetFrame can be 0 when we're trying to navigate a top-level frame
316 // that has a 0 opener. 316 // that has a 0 opener.
317 if (!targetFrame) 317 if (!targetFrame)
318 return false; 318 return false;
319 319
320 const bool isLocalActiveOrigin = activeSecurityOrigin->isLocal(); 320 const bool isLocalActiveOrigin = activeSecurityOrigin->isLocal();
321 for (Frame* ancestorFrame = targetFrame; ancestorFrame; ancestorFrame = ance storFrame->tree()->parent()) { 321 for (Frame* ancestorFrame = targetFrame; ancestorFrame; ancestorFrame = ance storFrame->tree().parent()) {
322 Document* ancestorDocument = ancestorFrame->document(); 322 Document* ancestorDocument = ancestorFrame->document();
323 // FIXME: Should be an ASSERT? Frames should alway have documents. 323 // FIXME: Should be an ASSERT? Frames should alway have documents.
324 if (!ancestorDocument) 324 if (!ancestorDocument)
325 return true; 325 return true;
326 326
327 const SecurityOrigin* ancestorSecurityOrigin = ancestorDocument->securit yOrigin(); 327 const SecurityOrigin* ancestorSecurityOrigin = ancestorDocument->securit yOrigin();
328 if (activeSecurityOrigin->canAccess(ancestorSecurityOrigin)) 328 if (activeSecurityOrigin->canAccess(ancestorSecurityOrigin))
329 return true; 329 return true;
330 330
331 // Allow file URL descendant navigation even when allowFileAccessFromFil eURLs is false. 331 // Allow file URL descendant navigation even when allowFileAccessFromFil eURLs is false.
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 } 945 }
946 default: 946 default:
947 if (source->isShadowRoot()) { 947 if (source->isShadowRoot()) {
948 // ShadowRoot cannot disconnect itself from the host node. 948 // ShadowRoot cannot disconnect itself from the host node.
949 es.throwUninformativeAndGenericDOMException(HierarchyRequestError); 949 es.throwUninformativeAndGenericDOMException(HierarchyRequestError);
950 return 0; 950 return 0;
951 } 951 }
952 952
953 if (source->isFrameOwnerElement()) { 953 if (source->isFrameOwnerElement()) {
954 HTMLFrameOwnerElement* frameOwnerElement = toHTMLFrameOwnerElement(s ource.get()); 954 HTMLFrameOwnerElement* frameOwnerElement = toHTMLFrameOwnerElement(s ource.get());
955 if (frame() && frame()->tree()->isDescendantOf(frameOwnerElement->co ntentFrame())) { 955 if (frame() && frame()->tree().isDescendantOf(frameOwnerElement->con tentFrame())) {
956 es.throwUninformativeAndGenericDOMException(HierarchyRequestErro r); 956 es.throwUninformativeAndGenericDOMException(HierarchyRequestErro r);
957 return 0; 957 return 0;
958 } 958 }
959 } 959 }
960 if (source->parentNode()) { 960 if (source->parentNode()) {
961 source->parentNode()->removeChild(source.get(), es); 961 source->parentNode()->removeChild(source.get(), es);
962 if (es.hadException()) 962 if (es.hadException())
963 return 0; 963 return 0;
964 } 964 }
965 } 965 }
(...skipping 1755 matching lines...) Expand 10 before | Expand all | Expand 10 after
2721 if (!m_frame) 2721 if (!m_frame)
2722 return false; 2722 return false;
2723 2723
2724 // FIXME: We shouldn't call this function without a target frame, but 2724 // FIXME: We shouldn't call this function without a target frame, but
2725 // fast/forms/submit-to-blank-multiple-times.html depends on this function 2725 // fast/forms/submit-to-blank-multiple-times.html depends on this function
2726 // returning true when supplied with a 0 targetFrame. 2726 // returning true when supplied with a 0 targetFrame.
2727 if (!targetFrame) 2727 if (!targetFrame)
2728 return true; 2728 return true;
2729 2729
2730 // Frame-busting is generally allowed, but blocked for sandboxed frames lack ing the 'allow-top-navigation' flag. 2730 // Frame-busting is generally allowed, but blocked for sandboxed frames lack ing the 'allow-top-navigation' flag.
2731 if (!isSandboxed(SandboxTopNavigation) && targetFrame == m_frame->tree()->to p()) 2731 if (!isSandboxed(SandboxTopNavigation) && targetFrame == m_frame->tree().top ())
2732 return true; 2732 return true;
2733 2733
2734 if (isSandboxed(SandboxNavigation)) { 2734 if (isSandboxed(SandboxNavigation)) {
2735 if (targetFrame->tree()->isDescendantOf(m_frame)) 2735 if (targetFrame->tree().isDescendantOf(m_frame))
2736 return true; 2736 return true;
2737 2737
2738 const char* reason = "The frame attempting navigation is sandboxed, and is therefore disallowed from navigating its ancestors."; 2738 const char* reason = "The frame attempting navigation is sandboxed, and is therefore disallowed from navigating its ancestors.";
2739 if (isSandboxed(SandboxTopNavigation) && targetFrame == m_frame->tree()- >top()) 2739 if (isSandboxed(SandboxTopNavigation) && targetFrame == m_frame->tree(). top())
2740 reason = "The frame attempting navigation of the top-level window is sandboxed, but the 'allow-top-navigation' flag is not set."; 2740 reason = "The frame attempting navigation of the top-level window is sandboxed, but the 'allow-top-navigation' flag is not set.";
2741 2741
2742 printNavigationErrorMessage(targetFrame, url(), reason); 2742 printNavigationErrorMessage(targetFrame, url(), reason);
2743 return false; 2743 return false;
2744 } 2744 }
2745 2745
2746 // This is the normal case. A document can navigate its decendant frames, 2746 // This is the normal case. A document can navigate its decendant frames,
2747 // or, more generally, a document can navigate a frame if the document is 2747 // or, more generally, a document can navigate a frame if the document is
2748 // in the same origin as any of that frame's ancestors (in the frame 2748 // in the same origin as any of that frame's ancestors (in the frame
2749 // hierarchy). 2749 // hierarchy).
2750 // 2750 //
2751 // See http://www.adambarth.com/papers/2008/barth-jackson-mitchell.pdf for 2751 // See http://www.adambarth.com/papers/2008/barth-jackson-mitchell.pdf for
2752 // historical information about this security check. 2752 // historical information about this security check.
2753 if (canAccessAncestor(securityOrigin(), targetFrame)) 2753 if (canAccessAncestor(securityOrigin(), targetFrame))
2754 return true; 2754 return true;
2755 2755
2756 // Top-level frames are easier to navigate than other frames because they 2756 // Top-level frames are easier to navigate than other frames because they
2757 // display their URLs in the address bar (in most browsers). However, there 2757 // display their URLs in the address bar (in most browsers). However, there
2758 // are still some restrictions on navigation to avoid nuisance attacks. 2758 // are still some restrictions on navigation to avoid nuisance attacks.
2759 // Specifically, a document can navigate a top-level frame if that frame 2759 // Specifically, a document can navigate a top-level frame if that frame
2760 // opened the document or if the document is the same-origin with any of 2760 // opened the document or if the document is the same-origin with any of
2761 // the top-level frame's opener's ancestors (in the frame hierarchy). 2761 // the top-level frame's opener's ancestors (in the frame hierarchy).
2762 // 2762 //
2763 // In both of these cases, the document performing the navigation is in 2763 // In both of these cases, the document performing the navigation is in
2764 // some way related to the frame being navigate (e.g., by the "opener" 2764 // some way related to the frame being navigate (e.g., by the "opener"
2765 // and/or "parent" relation). Requiring some sort of relation prevents a 2765 // and/or "parent" relation). Requiring some sort of relation prevents a
2766 // document from navigating arbitrary, unrelated top-level frames. 2766 // document from navigating arbitrary, unrelated top-level frames.
2767 if (!targetFrame->tree()->parent()) { 2767 if (!targetFrame->tree().parent()) {
2768 if (targetFrame == m_frame->loader()->opener()) 2768 if (targetFrame == m_frame->loader()->opener())
2769 return true; 2769 return true;
2770 2770
2771 if (canAccessAncestor(securityOrigin(), targetFrame->loader()->opener()) ) 2771 if (canAccessAncestor(securityOrigin(), targetFrame->loader()->opener()) )
2772 return true; 2772 return true;
2773 } 2773 }
2774 2774
2775 printNavigationErrorMessage(targetFrame, url(), "The frame attempting naviga tion is neither same-origin with the target, nor is it the target's parent or op ener."); 2775 printNavigationErrorMessage(targetFrame, url(), "The frame attempting naviga tion is neither same-origin with the target, nor is it the target's parent or op ener.");
2776 return false; 2776 return false;
2777 } 2777 }
2778 2778
2779 Frame* Document::findUnsafeParentScrollPropagationBoundary() 2779 Frame* Document::findUnsafeParentScrollPropagationBoundary()
2780 { 2780 {
2781 Frame* currentFrame = m_frame; 2781 Frame* currentFrame = m_frame;
2782 Frame* ancestorFrame = currentFrame->tree()->parent(); 2782 Frame* ancestorFrame = currentFrame->tree().parent();
2783 2783
2784 while (ancestorFrame) { 2784 while (ancestorFrame) {
2785 if (!ancestorFrame->document()->securityOrigin()->canAccess(securityOrig in())) 2785 if (!ancestorFrame->document()->securityOrigin()->canAccess(securityOrig in()))
2786 return currentFrame; 2786 return currentFrame;
2787 currentFrame = ancestorFrame; 2787 currentFrame = ancestorFrame;
2788 ancestorFrame = ancestorFrame->tree()->parent(); 2788 ancestorFrame = ancestorFrame->tree().parent();
2789 } 2789 }
2790 return 0; 2790 return 0;
2791 } 2791 }
2792 2792
2793 2793
2794 void Document::seamlessParentUpdatedStylesheets() 2794 void Document::seamlessParentUpdatedStylesheets()
2795 { 2795 {
2796 m_styleEngine->didModifySeamlessParentStyleSheet(); 2796 m_styleEngine->didModifySeamlessParentStyleSheet();
2797 styleResolverChanged(RecalcStyleImmediately); 2797 styleResolverChanged(RecalcStyleImmediately);
2798 } 2798 }
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
3204 updateStyleIfNeeded(); 3204 updateStyleIfNeeded();
3205 } 3205 }
3206 3206
3207 void Document::notifySeamlessChildDocumentsOfStylesheetUpdate() const 3207 void Document::notifySeamlessChildDocumentsOfStylesheetUpdate() const
3208 { 3208 {
3209 // If we're not in a frame yet any potential child documents won't have a St yleResolver to update. 3209 // If we're not in a frame yet any potential child documents won't have a St yleResolver to update.
3210 if (!frame()) 3210 if (!frame())
3211 return; 3211 return;
3212 3212
3213 // Seamless child frames are expected to notify their seamless children recu rsively, so we only do direct children. 3213 // Seamless child frames are expected to notify their seamless children recu rsively, so we only do direct children.
3214 for (Frame* child = frame()->tree()->firstChild(); child; child = child->tre e()->nextSibling()) { 3214 for (Frame* child = frame()->tree().firstChild(); child; child = child->tree ().nextSibling()) {
3215 Document* childDocument = child->document(); 3215 Document* childDocument = child->document();
3216 if (childDocument->shouldDisplaySeamlesslyWithParent()) { 3216 if (childDocument->shouldDisplaySeamlesslyWithParent()) {
3217 ASSERT(childDocument->seamlessParentIFrame()->document() == this); 3217 ASSERT(childDocument->seamlessParentIFrame()->document() == this);
3218 childDocument->seamlessParentUpdatedStylesheets(); 3218 childDocument->seamlessParentUpdatedStylesheets();
3219 } 3219 }
3220 } 3220 }
3221 } 3221 }
3222 3222
3223 void Document::setHoverNode(PassRefPtr<Node> newHoverNode) 3223 void Document::setHoverNode(PassRefPtr<Node> newHoverNode)
3224 { 3224 {
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after
4111 { 4111 {
4112 return command(this, commandName).value(); 4112 return command(this, commandName).value();
4113 } 4113 }
4114 4114
4115 KURL Document::openSearchDescriptionURL() 4115 KURL Document::openSearchDescriptionURL()
4116 { 4116 {
4117 static const char* const openSearchMIMEType = "application/opensearchdescrip tion+xml"; 4117 static const char* const openSearchMIMEType = "application/opensearchdescrip tion+xml";
4118 static const char* const openSearchRelation = "search"; 4118 static const char* const openSearchRelation = "search";
4119 4119
4120 // FIXME: Why do only top-level frames have openSearchDescriptionURLs? 4120 // FIXME: Why do only top-level frames have openSearchDescriptionURLs?
4121 if (!frame() || frame()->tree()->parent()) 4121 if (!frame() || frame()->tree().parent())
4122 return KURL(); 4122 return KURL();
4123 4123
4124 // FIXME: Why do we need to wait for FrameStateComplete? 4124 // FIXME: Why do we need to wait for FrameStateComplete?
4125 if (frame()->loader()->state() != FrameStateComplete) 4125 if (frame()->loader()->state() != FrameStateComplete)
4126 return KURL(); 4126 return KURL();
4127 4127
4128 if (!head()) 4128 if (!head())
4129 return KURL(); 4129 return KURL();
4130 4130
4131 RefPtr<HTMLCollection> children = head()->children(); 4131 RefPtr<HTMLCollection> children = head()->children();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4173 } 4173 }
4174 4174
4175 void Document::setTransformSource(PassOwnPtr<TransformSource> source) 4175 void Document::setTransformSource(PassOwnPtr<TransformSource> source)
4176 { 4176 {
4177 m_transformSource = source; 4177 m_transformSource = source;
4178 } 4178 }
4179 4179
4180 void Document::setDesignMode(InheritedBool value) 4180 void Document::setDesignMode(InheritedBool value)
4181 { 4181 {
4182 m_designMode = value; 4182 m_designMode = value;
4183 for (Frame* frame = m_frame; frame && frame->document(); frame = frame->tree ()->traverseNext(m_frame)) 4183 for (Frame* frame = m_frame; frame && frame->document(); frame = frame->tree ().traverseNext(m_frame))
4184 frame->document()->setNeedsStyleRecalc(); 4184 frame->document()->setNeedsStyleRecalc();
4185 } 4185 }
4186 4186
4187 Document::InheritedBool Document::getDesignMode() const 4187 Document::InheritedBool Document::getDesignMode() const
4188 { 4188 {
4189 return m_designMode; 4189 return m_designMode;
4190 } 4190 }
4191 4191
4192 bool Document::inDesignMode() const 4192 bool Document::inDesignMode() const
4193 { 4193 {
4194 for (const Document* d = this; d; d = d->parentDocument()) { 4194 for (const Document* d = this; d; d = d->parentDocument()) {
4195 if (d->m_designMode != inherit) 4195 if (d->m_designMode != inherit)
4196 return d->m_designMode; 4196 return d->m_designMode;
4197 } 4197 }
4198 return false; 4198 return false;
4199 } 4199 }
4200 4200
4201 Document* Document::parentDocument() const 4201 Document* Document::parentDocument() const
4202 { 4202 {
4203 if (!m_frame) 4203 if (!m_frame)
4204 return 0; 4204 return 0;
4205 Frame* parent = m_frame->tree()->parent(); 4205 Frame* parent = m_frame->tree().parent();
4206 if (!parent) 4206 if (!parent)
4207 return 0; 4207 return 0;
4208 return parent->document(); 4208 return parent->document();
4209 } 4209 }
4210 4210
4211 Document* Document::topDocument() const 4211 Document* Document::topDocument() const
4212 { 4212 {
4213 Document* doc = const_cast<Document*>(this); 4213 Document* doc = const_cast<Document*>(this);
4214 Element* element; 4214 Element* element;
4215 while ((element = doc->ownerElement())) 4215 while ((element = doc->ownerElement()))
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
4529 } 4529 }
4530 4530
4531 m_cookieURL = ownerFrame->document()->cookieURL(); 4531 m_cookieURL = ownerFrame->document()->cookieURL();
4532 // We alias the SecurityOrigins to match Firefox, see Bug 15313 4532 // We alias the SecurityOrigins to match Firefox, see Bug 15313
4533 // https://bugs.webkit.org/show_bug.cgi?id=15313 4533 // https://bugs.webkit.org/show_bug.cgi?id=15313
4534 setSecurityOrigin(ownerFrame->document()->securityOrigin()); 4534 setSecurityOrigin(ownerFrame->document()->securityOrigin());
4535 } 4535 }
4536 4536
4537 void Document::initContentSecurityPolicy(const ContentSecurityPolicyResponseHead ers& headers) 4537 void Document::initContentSecurityPolicy(const ContentSecurityPolicyResponseHead ers& headers)
4538 { 4538 {
4539 if (m_frame && m_frame->tree()->parent() && (shouldInheritSecurityOriginFrom Owner(m_url) || isPluginDocument())) 4539 if (m_frame && m_frame->tree().parent() && (shouldInheritSecurityOriginFromO wner(m_url) || isPluginDocument()))
4540 contentSecurityPolicy()->copyStateFrom(m_frame->tree()->parent()->docume nt()->contentSecurityPolicy()); 4540 contentSecurityPolicy()->copyStateFrom(m_frame->tree().parent()->documen t()->contentSecurityPolicy());
4541 contentSecurityPolicy()->didReceiveHeaders(headers); 4541 contentSecurityPolicy()->didReceiveHeaders(headers);
4542 } 4542 }
4543 4543
4544 bool Document::allowInlineEventHandlers(Node* node, EventListener* listener, con st String& contextURL, const WTF::OrdinalNumber& contextLine) 4544 bool Document::allowInlineEventHandlers(Node* node, EventListener* listener, con st String& contextURL, const WTF::OrdinalNumber& contextLine)
4545 { 4545 {
4546 if (!contentSecurityPolicy()->allowInlineEventHandlers(contextURL, contextLi ne)) 4546 if (!contentSecurityPolicy()->allowInlineEventHandlers(contextURL, contextLi ne))
4547 return false; 4547 return false;
4548 4548
4549 // HTML says that inline script needs browsing context to create its executi on environment. 4549 // HTML says that inline script needs browsing context to create its executi on environment.
4550 // http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.ht ml#event-handler-attributes 4550 // http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.ht ml#event-handler-attributes
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
4967 return; 4967 return;
4968 } 4968 }
4969 4969
4970 Page* page = this->page(); 4970 Page* page = this->page();
4971 if (!page) 4971 if (!page)
4972 return; 4972 return;
4973 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator( )) 4973 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator( ))
4974 scrollingCoordinator->touchEventTargetRectsDidChange(this); 4974 scrollingCoordinator->touchEventTargetRectsDidChange(this);
4975 if (m_touchEventTargets->size()) 4975 if (m_touchEventTargets->size())
4976 return; 4976 return;
4977 for (const Frame* frame = page->mainFrame(); frame; frame = frame->tree()->t raverseNext()) { 4977 for (const Frame* frame = page->mainFrame(); frame; frame = frame->tree().tr averseNext()) {
4978 if (frame->document() && frame->document()->hasTouchEventHandlers()) 4978 if (frame->document() && frame->document()->hasTouchEventHandlers())
4979 return; 4979 return;
4980 } 4980 }
4981 page->chrome().client().needTouchEvents(false); 4981 page->chrome().client().needTouchEvents(false);
4982 } 4982 }
4983 4983
4984 void Document::didRemoveEventTargetNode(Node* handler) 4984 void Document::didRemoveEventTargetNode(Node* handler)
4985 { 4985 {
4986 if (m_touchEventTargets && !m_touchEventTargets->isEmpty()) { 4986 if (m_touchEventTargets && !m_touchEventTargets->isEmpty()) {
4987 if (handler == this) 4987 if (handler == this)
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
5348 void Document::modifiedStyleSheet(StyleSheet* sheet, RecalcStyleTime when, Style ResolverUpdateMode updateMode) 5348 void Document::modifiedStyleSheet(StyleSheet* sheet, RecalcStyleTime when, Style ResolverUpdateMode updateMode)
5349 { 5349 {
5350 if (!isActive()) 5350 if (!isActive())
5351 return; 5351 return;
5352 5352
5353 styleEngine()->modifiedStyleSheet(sheet); 5353 styleEngine()->modifiedStyleSheet(sheet);
5354 styleResolverChanged(when, updateMode); 5354 styleResolverChanged(when, updateMode);
5355 } 5355 }
5356 5356
5357 } // namespace WebCore 5357 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/custom/V8WindowCustom.cpp ('k') | Source/core/dom/DocumentInit.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698