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 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 if (WebFrame::opener() && !opener && m_client) | 637 if (WebFrame::opener() && !opener && m_client) |
638 m_client->didDisownOpener(this); | 638 m_client->didDisownOpener(this); |
639 | 639 |
640 WebFrame::setOpener(opener); | 640 WebFrame::setOpener(opener); |
641 | 641 |
642 ASSERT(m_frame); | 642 ASSERT(m_frame); |
643 if (m_frame && m_frame->document()) | 643 if (m_frame && m_frame->document()) |
644 m_frame->document()->initSecurityContext(); | 644 m_frame->document()->initSecurityContext(); |
645 } | 645 } |
646 | 646 |
| 647 void WebLocalFrameImpl::initializeAsMainFrame(WebView* view) |
| 648 { |
| 649 Page* page = toWebViewImpl(view)->page(); |
| 650 setWebCoreFrame(LocalFrame::create(&m_frameLoaderClientImpl, &page->frameHos
t(), 0)); |
| 651 |
| 652 // We must call init() after m_frame is assigned because it is referenced |
| 653 // during init(). |
| 654 m_frame->init(); |
| 655 } |
| 656 |
647 // FIXME: These methods should move into WebFrame once FrameTree is no longer | 657 // FIXME: These methods should move into WebFrame once FrameTree is no longer |
648 // dependent on LocalFrame. | 658 // dependent on LocalFrame. |
649 void WebLocalFrameImpl::appendChild(WebFrame* child) | 659 void WebLocalFrameImpl::appendChild(WebFrame* child) |
650 { | 660 { |
651 WebFrame::appendChild(child); | 661 WebFrame::appendChild(child); |
652 frame()->tree().invalidateScopedChildCount(); | 662 frame()->tree().invalidateScopedChildCount(); |
653 } | 663 } |
654 | 664 |
655 void WebLocalFrameImpl::removeChild(WebFrame* child) | 665 void WebLocalFrameImpl::removeChild(WebFrame* child) |
656 { | 666 { |
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1639 provideNotification(*m_frame, notificationPresenter.release()); | 1649 provideNotification(*m_frame, notificationPresenter.release()); |
1640 provideUserMediaTo(*m_frame, &m_userMediaClientImpl); | 1650 provideUserMediaTo(*m_frame, &m_userMediaClientImpl); |
1641 provideGeolocationTo(*m_frame, m_geolocationClientProxy.get()); | 1651 provideGeolocationTo(*m_frame, m_geolocationClientProxy.get()); |
1642 m_geolocationClientProxy->setController(GeolocationController::from(m_fr
ame.get())); | 1652 m_geolocationClientProxy->setController(GeolocationController::from(m_fr
ame.get())); |
1643 provideMIDITo(*m_frame, MIDIClientProxy::create(m_client ? m_client->web
MIDIClient() : 0)); | 1653 provideMIDITo(*m_frame, MIDIClientProxy::create(m_client ? m_client->web
MIDIClient() : 0)); |
1644 if (RuntimeEnabledFeatures::screenOrientationEnabled()) | 1654 if (RuntimeEnabledFeatures::screenOrientationEnabled()) |
1645 ScreenOrientationController::provideTo(*m_frame, m_client ? m_client
->webScreenOrientationClient() : 0); | 1655 ScreenOrientationController::provideTo(*m_frame, m_client ? m_client
->webScreenOrientationClient() : 0); |
1646 } | 1656 } |
1647 } | 1657 } |
1648 | 1658 |
1649 void WebLocalFrameImpl::initializeAsMainFrame(WebCore::Page* page) | |
1650 { | |
1651 setWebCoreFrame(LocalFrame::create(&m_frameLoaderClientImpl, &page->frameHos
t(), 0)); | |
1652 | |
1653 // We must call init() after m_frame is assigned because it is referenced | |
1654 // during init(). | |
1655 m_frame->init(); | |
1656 } | |
1657 | |
1658 PassRefPtr<LocalFrame> WebLocalFrameImpl::createChildFrame(const FrameLoadReques
t& request, HTMLFrameOwnerElement* ownerElement) | 1659 PassRefPtr<LocalFrame> WebLocalFrameImpl::createChildFrame(const FrameLoadReques
t& request, HTMLFrameOwnerElement* ownerElement) |
1659 { | 1660 { |
1660 ASSERT(m_client); | 1661 ASSERT(m_client); |
1661 WebLocalFrameImpl* webframe = toWebLocalFrameImpl(m_client->createChildFrame
(this, request.frameName())); | 1662 // Protect a reference to the new child frame, in case it gets detached. |
1662 if (!webframe) | 1663 RefPtr<WebLocalFrameImpl> child = toWebLocalFrameImpl(m_client->createChildF
rame(this, request.frameName())); |
| 1664 if (!child) |
1663 return nullptr; | 1665 return nullptr; |
1664 | 1666 |
1665 RefPtr<LocalFrame> childFrame = LocalFrame::create(&webframe->m_frameLoaderC
lientImpl, frame()->host(), ownerElement); | |
1666 webframe->setWebCoreFrame(childFrame); | |
1667 | |
1668 // FIXME: Using subResourceAttributeName as fallback is not a perfect | 1667 // FIXME: Using subResourceAttributeName as fallback is not a perfect |
1669 // solution. subResourceAttributeName returns just one attribute name. The | 1668 // solution. subResourceAttributeName returns just one attribute name. The |
1670 // element might not have the attribute, and there might be other attributes | 1669 // element might not have the attribute, and there might be other attributes |
1671 // which can identify the element. | 1670 // which can identify the element. |
1672 childFrame->tree().setName(request.frameName(), ownerElement->getAttribute(o
wnerElement->subResourceAttributeName())); | 1671 child->initializeAsChildFrame(frame()->host(), ownerElement, request.frameNa
me(), ownerElement->getAttribute(ownerElement->subResourceAttributeName())); |
1673 | 1672 // Initializing the WebCore frame may cause the new child to be detached, si
nce it may dispatch a load event in the parent. |
1674 // FIXME: This comment is not quite accurate anymore. | 1673 if (!child->frame()) |
1675 // LocalFrame::init() can trigger onload event in the parent frame, | |
1676 // which may detach this frame and trigger a null-pointer access | |
1677 // in FrameTree::removeChild. Move init() after appendChild call | |
1678 // so that webframe->mFrame is in the tree before triggering | |
1679 // onload event handler. | |
1680 // Because the event handler may set webframe->mFrame to null, | |
1681 // it is necessary to check the value after calling init() and | |
1682 // return without loading URL. | |
1683 // NOTE: m_client will be null if this frame has been detached. | |
1684 // (b:791612) | |
1685 childFrame->init(); // create an empty document | |
1686 if (!childFrame->tree().parent()) | |
1687 return nullptr; | 1674 return nullptr; |
1688 | 1675 |
1689 // If we're moving in the back/forward list, we might want to replace the co
ntent | 1676 // If we're moving in the back/forward list, we might want to replace the co
ntent |
1690 // of this child frame with whatever was there at that point. | 1677 // of this child frame with whatever was there at that point. |
1691 RefPtr<HistoryItem> childItem; | 1678 RefPtr<HistoryItem> childItem; |
1692 if (isBackForwardLoadType(frame()->loader().loadType()) && !frame()->documen
t()->loadEventFinished()) | 1679 if (isBackForwardLoadType(frame()->loader().loadType()) && !frame()->documen
t()->loadEventFinished()) |
1693 childItem = PassRefPtr<HistoryItem>(webframe->client()->historyItemForNe
wChildFrame(webframe)); | 1680 childItem = PassRefPtr<HistoryItem>(child->client()->historyItemForNewCh
ildFrame(child.get())); |
1694 | 1681 |
1695 if (childItem) | 1682 if (childItem) |
1696 childFrame->loader().loadHistoryItem(childItem.get()); | 1683 child->frame()->loader().loadHistoryItem(childItem.get()); |
1697 else | 1684 else |
1698 childFrame->loader().load(FrameLoadRequest(0, request.resourceRequest(),
"_self")); | 1685 child->frame()->loader().load(FrameLoadRequest(0, request.resourceReques
t(), "_self")); |
1699 | 1686 |
1700 // A synchronous navigation (about:blank) would have already processed | 1687 // Note a synchronous navigation (about:blank) would have already processed |
1701 // onload, so it is possible for the frame to have already been destroyed by | 1688 // onload, so it is possible for the child frame to have already been destro
yed by |
1702 // script in the page. | 1689 // script in the page. |
1703 // NOTE: m_client will be null if this frame has been detached. | 1690 return child->frame(); |
1704 if (!childFrame->tree().parent()) | |
1705 return nullptr; | |
1706 | |
1707 return childFrame.release(); | |
1708 } | 1691 } |
1709 | 1692 |
1710 void WebLocalFrameImpl::didChangeContentsSize(const IntSize& size) | 1693 void WebLocalFrameImpl::didChangeContentsSize(const IntSize& size) |
1711 { | 1694 { |
1712 // This is only possible on the main frame. | 1695 // This is only possible on the main frame. |
1713 if (m_textFinder && m_textFinder->totalMatchCount() > 0) { | 1696 if (m_textFinder && m_textFinder->totalMatchCount() > 0) { |
1714 ASSERT(!parent()); | 1697 ASSERT(!parent()); |
1715 m_textFinder->increaseMarkerVersion(); | 1698 m_textFinder->increaseMarkerVersion(); |
1716 } | 1699 } |
1717 } | 1700 } |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1943 } | 1926 } |
1944 | 1927 |
1945 void WebLocalFrameImpl::invalidateAll() const | 1928 void WebLocalFrameImpl::invalidateAll() const |
1946 { | 1929 { |
1947 ASSERT(frame() && frame()->view()); | 1930 ASSERT(frame() && frame()->view()); |
1948 FrameView* view = frame()->view(); | 1931 FrameView* view = frame()->view(); |
1949 view->invalidateRect(view->frameRect()); | 1932 view->invalidateRect(view->frameRect()); |
1950 invalidateScrollbar(); | 1933 invalidateScrollbar(); |
1951 } | 1934 } |
1952 | 1935 |
| 1936 void WebLocalFrameImpl::initializeAsChildFrame(FrameHost* host, FrameOwner* owne
r, const AtomicString& name, const AtomicString& fallbackName) |
| 1937 { |
| 1938 setWebCoreFrame(LocalFrame::create(&m_frameLoaderClientImpl, host, owner)); |
| 1939 frame()->tree().setName(name, fallbackName); |
| 1940 // May dispatch JS events; frame() may be null after this. |
| 1941 frame()->init(); |
| 1942 } |
| 1943 |
1953 } // namespace blink | 1944 } // namespace blink |
OLD | NEW |