Index: Source/core/dom/Document.cpp |
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp |
index 8518bf998c9e67807636a52dd56604938a5e5e73..b24d21ef2aed883bc61cfbc933a5afbccb87e101 100644 |
--- a/Source/core/dom/Document.cpp |
+++ b/Source/core/dom/Document.cpp |
@@ -287,32 +287,29 @@ static bool shouldInheritSecurityOriginFromOwner(const KURL& url) |
return url.isEmpty() || url.isBlankURL(); |
} |
-static Widget* widgetForElement(Element* focusedElement) |
+static Widget* widgetForElement(const Element& focusedElement) |
{ |
- if (!focusedElement) |
- return 0; |
- RenderObject* renderer = focusedElement->renderer(); |
+ RenderObject* renderer = focusedElement.renderer(); |
if (!renderer || !renderer->isWidget()) |
return 0; |
return toRenderWidget(renderer)->widget(); |
} |
-static bool acceptsEditingFocus(Element* element) |
+static bool acceptsEditingFocus(const Element& element) |
{ |
- ASSERT(element); |
- ASSERT(element->rendererIsEditable()); |
+ ASSERT(element.rendererIsEditable()); |
- return element->document().frame() && element->rootEditableElement(); |
+ return element.document().frame() && element.rootEditableElement(); |
} |
-static bool canAccessAncestor(const SecurityOrigin* activeSecurityOrigin, Frame* targetFrame) |
+static bool canAccessAncestor(const SecurityOrigin& activeSecurityOrigin, Frame* targetFrame) |
{ |
// targetFrame can be 0 when we're trying to navigate a top-level frame |
// that has a 0 opener. |
if (!targetFrame) |
return false; |
- const bool isLocalActiveOrigin = activeSecurityOrigin->isLocal(); |
+ const bool isLocalActiveOrigin = activeSecurityOrigin.isLocal(); |
for (Frame* ancestorFrame = targetFrame; ancestorFrame; ancestorFrame = ancestorFrame->tree().parent()) { |
Document* ancestorDocument = ancestorFrame->document(); |
// FIXME: Should be an ASSERT? Frames should alway have documents. |
@@ -320,7 +317,7 @@ static bool canAccessAncestor(const SecurityOrigin* activeSecurityOrigin, Frame* |
return true; |
const SecurityOrigin* ancestorSecurityOrigin = ancestorDocument->securityOrigin(); |
- if (activeSecurityOrigin->canAccess(ancestorSecurityOrigin)) |
+ if (activeSecurityOrigin.canAccess(ancestorSecurityOrigin)) |
return true; |
// Allow file URL descendant navigation even when allowFileAccessFromFileURLs is false. |
@@ -333,12 +330,12 @@ static bool canAccessAncestor(const SecurityOrigin* activeSecurityOrigin, Frame* |
return false; |
} |
-static void printNavigationErrorMessage(Frame* frame, const KURL& activeURL, const char* reason) |
+static void printNavigationErrorMessage(const Frame& frame, const KURL& activeURL, const char* reason) |
{ |
- String message = "Unsafe JavaScript attempt to initiate navigation for frame with URL '" + frame->document()->url().string() + "' from frame with URL '" + activeURL.string() + "'. " + reason + "\n"; |
+ String message = "Unsafe JavaScript attempt to initiate navigation for frame with URL '" + frame.document()->url().string() + "' from frame with URL '" + activeURL.string() + "'. " + reason + "\n"; |
// FIXME: should we print to the console of the document performing the navigation instead? |
- frame->domWindow()->printErrorMessage(message); |
+ frame.domWindow()->printErrorMessage(message); |
} |
uint64_t Document::s_globalTreeVersion = 0; |
@@ -2734,10 +2731,13 @@ bool Document::canNavigate(Frame* targetFrame) |
if (isSandboxed(SandboxTopNavigation) && targetFrame == m_frame->tree().top()) |
reason = "The frame attempting navigation of the top-level window is sandboxed, but the 'allow-top-navigation' flag is not set."; |
- printNavigationErrorMessage(targetFrame, url(), reason); |
+ printNavigationErrorMessage(*targetFrame, url(), reason); |
return false; |
} |
+ ASSERT(securityOrigin()); |
+ SecurityOrigin& origin = *securityOrigin(); |
+ |
// This is the normal case. A document can navigate its decendant frames, |
// or, more generally, a document can navigate a frame if the document is |
// in the same origin as any of that frame's ancestors (in the frame |
@@ -2745,7 +2745,7 @@ bool Document::canNavigate(Frame* targetFrame) |
// |
// See http://www.adambarth.com/papers/2008/barth-jackson-mitchell.pdf for |
// historical information about this security check. |
- if (canAccessAncestor(securityOrigin(), targetFrame)) |
+ if (canAccessAncestor(origin, targetFrame)) |
return true; |
// Top-level frames are easier to navigate than other frames because they |
@@ -2763,11 +2763,11 @@ bool Document::canNavigate(Frame* targetFrame) |
if (targetFrame == m_frame->loader().opener()) |
return true; |
- if (canAccessAncestor(securityOrigin(), targetFrame->loader().opener())) |
+ if (canAccessAncestor(origin, targetFrame->loader().opener())) |
return true; |
} |
- printNavigationErrorMessage(targetFrame, url(), "The frame attempting navigation is neither same-origin with the target, nor is it the target's parent or opener."); |
+ printNavigationErrorMessage(*targetFrame, url(), "The frame attempting navigation is neither same-origin with the target, nor is it the target's parent or opener."); |
return false; |
} |
@@ -3349,7 +3349,7 @@ bool Document::setFocusedElement(PassRefPtr<Element> prpNewFocusedElement, Focus |
} |
if (view()) { |
- Widget* oldWidget = widgetForElement(oldFocusedElement.get()); |
+ Widget* oldWidget = widgetForElement(*oldFocusedElement); |
if (oldWidget) |
oldWidget->setFocus(false); |
else |
@@ -3363,7 +3363,7 @@ bool Document::setFocusedElement(PassRefPtr<Element> prpNewFocusedElement, Focus |
} |
if (newFocusedElement && newFocusedElement->isFocusable()) { |
- if (newFocusedElement->isRootEditableElement() && !acceptsEditingFocus(newFocusedElement.get())) { |
+ if (newFocusedElement->isRootEditableElement() && !acceptsEditingFocus(*newFocusedElement)) { |
// delegate blocks focus change |
focusChangeBlocked = true; |
goto SetFocusedElementDone; |
@@ -3405,14 +3405,14 @@ bool Document::setFocusedElement(PassRefPtr<Element> prpNewFocusedElement, Focus |
// eww, I suck. set the qt focus correctly |
// ### find a better place in the code for this |
if (view()) { |
- Widget* focusWidget = widgetForElement(m_focusedElement.get()); |
+ Widget* focusWidget = widgetForElement(*m_focusedElement); |
if (focusWidget) { |
// Make sure a widget has the right size before giving it focus. |
// Otherwise, we are testing edge cases of the Widget code. |
// Specifically, in WebCore this does not work well for text fields. |
updateLayout(); |
// Re-get the widget in case updating the layout changed things. |
- focusWidget = widgetForElement(m_focusedElement.get()); |
+ focusWidget = widgetForElement(*m_focusedElement); |
} |
if (focusWidget) |
focusWidget->setFocus(true); |