OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1663 setWebCoreFrame(LocalFrame::create(&m_frameLoaderClientImpl, &page->frameHos
t(), 0)); | 1663 setWebCoreFrame(LocalFrame::create(&m_frameLoaderClientImpl, &page->frameHos
t(), 0)); |
1664 | 1664 |
1665 // We must call init() after m_frame is assigned because it is referenced | 1665 // We must call init() after m_frame is assigned because it is referenced |
1666 // during init(). | 1666 // during init(). |
1667 m_frame->init(); | 1667 m_frame->init(); |
1668 } | 1668 } |
1669 | 1669 |
1670 PassRefPtr<LocalFrame> WebLocalFrameImpl::createChildFrame(const FrameLoadReques
t& request, HTMLFrameOwnerElement* ownerElement) | 1670 PassRefPtr<LocalFrame> WebLocalFrameImpl::createChildFrame(const FrameLoadReques
t& request, HTMLFrameOwnerElement* ownerElement) |
1671 { | 1671 { |
1672 ASSERT(m_client); | 1672 ASSERT(m_client); |
1673 WebLocalFrameImpl* webframe = toWebLocalFrameImpl(m_client->createChildFrame
(this, request.frameName())); | 1673 // Protect a reference to the new child frame, in case it gets detached. |
1674 if (!webframe) | 1674 RefPtr<WebLocalFrameImpl> child = toWebLocalFrameImpl(m_client->createChildF
rame(this, request.frameName())); |
| 1675 if (!child) |
1675 return nullptr; | 1676 return nullptr; |
1676 | 1677 |
1677 RefPtr<LocalFrame> childFrame = LocalFrame::create(&webframe->m_frameLoaderC
lientImpl, frame()->host(), ownerElement); | |
1678 webframe->setWebCoreFrame(childFrame); | |
1679 | |
1680 // FIXME: Using subResourceAttributeName as fallback is not a perfect | 1678 // FIXME: Using subResourceAttributeName as fallback is not a perfect |
1681 // solution. subResourceAttributeName returns just one attribute name. The | 1679 // solution. subResourceAttributeName returns just one attribute name. The |
1682 // element might not have the attribute, and there might be other attributes | 1680 // element might not have the attribute, and there might be other attributes |
1683 // which can identify the element. | 1681 // which can identify the element. |
1684 childFrame->tree().setName(request.frameName(), ownerElement->getAttribute(o
wnerElement->subResourceAttributeName())); | 1682 child->initializeAsChildFrame(frame()->host(), ownerElement, request.frameNa
me(), ownerElement->getAttribute(ownerElement->subResourceAttributeName())); |
1685 | 1683 // Initializing the WebCore frame may cause the new child to be detached, si
nce it may dispatch a load event in the parent. |
1686 // FIXME: This comment is not quite accurate anymore. | 1684 if (!child->frame()) |
1687 // LocalFrame::init() can trigger onload event in the parent frame, | |
1688 // which may detach this frame and trigger a null-pointer access | |
1689 // in FrameTree::removeChild. Move init() after appendChild call | |
1690 // so that webframe->mFrame is in the tree before triggering | |
1691 // onload event handler. | |
1692 // Because the event handler may set webframe->mFrame to null, | |
1693 // it is necessary to check the value after calling init() and | |
1694 // return without loading URL. | |
1695 // NOTE: m_client will be null if this frame has been detached. | |
1696 // (b:791612) | |
1697 childFrame->init(); // create an empty document | |
1698 if (!childFrame->tree().parent()) | |
1699 return nullptr; | 1685 return nullptr; |
1700 | 1686 |
1701 // If we're moving in the back/forward list, we might want to replace the co
ntent | 1687 // If we're moving in the back/forward list, we might want to replace the co
ntent |
1702 // of this child frame with whatever was there at that point. | 1688 // of this child frame with whatever was there at that point. |
1703 RefPtr<HistoryItem> childItem; | 1689 RefPtr<HistoryItem> childItem; |
1704 if (isBackForwardLoadType(frame()->loader().loadType()) && !frame()->documen
t()->loadEventFinished()) | 1690 if (isBackForwardLoadType(frame()->loader().loadType()) && !frame()->documen
t()->loadEventFinished()) |
1705 childItem = PassRefPtr<HistoryItem>(webframe->client()->historyItemForNe
wChildFrame(webframe)); | 1691 childItem = PassRefPtr<HistoryItem>(child->client()->historyItemForNewCh
ildFrame(child.get())); |
1706 | 1692 |
1707 if (childItem) | 1693 if (childItem) |
1708 childFrame->loader().loadHistoryItem(childItem.get()); | 1694 child->frame()->loader().loadHistoryItem(childItem.get()); |
1709 else | 1695 else |
1710 childFrame->loader().load(FrameLoadRequest(0, request.resourceRequest(),
"_self")); | 1696 child->frame()->loader().load(FrameLoadRequest(0, request.resourceReques
t(), "_self")); |
1711 | 1697 |
1712 // A synchronous navigation (about:blank) would have already processed | 1698 // Note a synchronous navigation (about:blank) would have already processed |
1713 // onload, so it is possible for the frame to have already been destroyed by | 1699 // onload, so it is possible for the child frame to have already been destro
yed by |
1714 // script in the page. | 1700 // script in the page. |
1715 // NOTE: m_client will be null if this frame has been detached. | 1701 return child->frame(); |
1716 if (!childFrame->tree().parent()) | |
1717 return nullptr; | |
1718 | |
1719 return childFrame.release(); | |
1720 } | 1702 } |
1721 | 1703 |
1722 void WebLocalFrameImpl::didChangeContentsSize(const IntSize& size) | 1704 void WebLocalFrameImpl::didChangeContentsSize(const IntSize& size) |
1723 { | 1705 { |
1724 // This is only possible on the main frame. | 1706 // This is only possible on the main frame. |
1725 if (m_textFinder && m_textFinder->totalMatchCount() > 0) { | 1707 if (m_textFinder && m_textFinder->totalMatchCount() > 0) { |
1726 ASSERT(!parent()); | 1708 ASSERT(!parent()); |
1727 m_textFinder->increaseMarkerVersion(); | 1709 m_textFinder->increaseMarkerVersion(); |
1728 } | 1710 } |
1729 } | 1711 } |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1955 } | 1937 } |
1956 | 1938 |
1957 void WebLocalFrameImpl::invalidateAll() const | 1939 void WebLocalFrameImpl::invalidateAll() const |
1958 { | 1940 { |
1959 ASSERT(frame() && frame()->view()); | 1941 ASSERT(frame() && frame()->view()); |
1960 FrameView* view = frame()->view(); | 1942 FrameView* view = frame()->view(); |
1961 view->invalidateRect(view->frameRect()); | 1943 view->invalidateRect(view->frameRect()); |
1962 invalidateScrollbar(); | 1944 invalidateScrollbar(); |
1963 } | 1945 } |
1964 | 1946 |
| 1947 void WebLocalFrameImpl::initializeAsChildFrame(FrameHost* host, FrameOwner* owne
r, const AtomicString& name, const AtomicString& fallbackName) |
| 1948 { |
| 1949 setWebCoreFrame(LocalFrame::create(&m_frameLoaderClientImpl, host, owner)); |
| 1950 frame()->tree().setName(name, fallbackName); |
| 1951 // May dispatch JS events; frame() may be null after this. |
| 1952 frame()->init(); |
| 1953 } |
| 1954 |
1965 } // namespace blink | 1955 } // namespace blink |
OLD | NEW |