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

Side by Side Diff: Source/web/WebFrameImpl.cpp

Issue 23506013: Make the embedder responsible for creating the WebFrame (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix style Created 7 years, 3 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
« no previous file with comments | « no previous file | Source/web/tests/WebFrameTest.cpp » ('j') | public/web/WebFrameClient.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // 43 //
44 // FrameLoader and Frame are formerly one object that was split apart because 44 // FrameLoader and Frame are formerly one object that was split apart because
45 // it got too big. They basically have the same lifetime, hence the double line. 45 // it got too big. They basically have the same lifetime, hence the double line.
46 // 46 //
47 // WebFrame is refcounted and has one ref on behalf of the FrameLoader/Frame. 47 // WebFrame is refcounted and has one ref on behalf of the FrameLoader/Frame.
48 // This is not a normal reference counted pointer because that would require 48 // This is not a normal reference counted pointer because that would require
49 // changing WebKit code that we don't control. Instead, it is created with this 49 // changing WebKit code that we don't control. Instead, it is created with this
50 // ref initially and it is removed when the FrameLoader is getting destroyed. 50 // ref initially and it is removed when the FrameLoader is getting destroyed.
51 // 51 //
52 // WebFrames are created in two places, first in WebViewImpl when the root 52 // WebFrames are created in two places, first in WebViewImpl when the root
53 // frame is created, and second in WebFrame::CreateChildFrame when sub-frames 53 // frame is created, and second in WebFrame::createChildFrame when sub-frames
54 // are created. WebKit will hook up this object to the FrameLoader/Frame 54 // are created. WebKit will hook up this object to the FrameLoader/Frame
55 // and the refcount will be correct. 55 // and the refcount will be correct.
56 // 56 //
57 // How frames are destroyed 57 // How frames are destroyed
58 // ------------------------ 58 // ------------------------
59 // 59 //
60 // The main frame is never destroyed and is re-used. The FrameLoader is re-used 60 // The main frame is never destroyed and is re-used. The FrameLoader is re-used
61 // and a reference to the main frame is kept by the Page. 61 // and a reference to the main frame is kept by the Page.
62 // 62 //
63 // When frame content is replaced, all subframes are destroyed. This happens 63 // When frame content is replaced, all subframes are destroyed. This happens
(...skipping 2009 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 WebString WebFrameImpl::layerTreeAsText(bool showDebugInfo) const 2073 WebString WebFrameImpl::layerTreeAsText(bool showDebugInfo) const
2074 { 2074 {
2075 if (!frame()) 2075 if (!frame())
2076 return WebString(); 2076 return WebString();
2077 2077
2078 return WebString(frame()->layerTreeAsText(showDebugInfo ? LayerTreeIncludesD ebugInfo : LayerTreeNormal)); 2078 return WebString(frame()->layerTreeAsText(showDebugInfo ? LayerTreeIncludesD ebugInfo : LayerTreeNormal));
2079 } 2079 }
2080 2080
2081 // WebFrameImpl public --------------------------------------------------------- 2081 // WebFrameImpl public ---------------------------------------------------------
2082 2082
2083 WebFrame* WebFrame::create(WebFrameClient* client)
2084 {
2085 return WebFrameImpl::create(client).leakRef();
2086 }
2087
2083 PassRefPtr<WebFrameImpl> WebFrameImpl::create(WebFrameClient* client) 2088 PassRefPtr<WebFrameImpl> WebFrameImpl::create(WebFrameClient* client)
2084 { 2089 {
2085 return adoptRef(new WebFrameImpl(client)); 2090 return adoptRef(new WebFrameImpl(client));
2086 } 2091 }
2087 2092
2088 WebFrameImpl::WebFrameImpl(WebFrameClient* client) 2093 WebFrameImpl::WebFrameImpl(WebFrameClient* client)
2089 : FrameDestructionObserver(0) 2094 : FrameDestructionObserver(0)
2090 , m_frameLoaderClient(this) 2095 , m_frameLoaderClient(this)
2091 , m_client(client) 2096 , m_client(client)
2092 , m_currentActiveMatchFrame(0) 2097 , m_currentActiveMatchFrame(0)
(...skipping 28 matching lines...) Expand all
2121 { 2126 {
2122 ASSERT(frame); 2127 ASSERT(frame);
2123 observeFrame(frame); 2128 observeFrame(frame);
2124 } 2129 }
2125 2130
2126 void WebFrameImpl::initializeAsMainFrame(WebCore::Page* page) 2131 void WebFrameImpl::initializeAsMainFrame(WebCore::Page* page)
2127 { 2132 {
2128 RefPtr<Frame> mainFrame = Frame::create(page, 0, &m_frameLoaderClient); 2133 RefPtr<Frame> mainFrame = Frame::create(page, 0, &m_frameLoaderClient);
2129 setWebCoreFrame(mainFrame.get()); 2134 setWebCoreFrame(mainFrame.get());
2130 2135
2131 // Add reference on behalf of FrameLoader. See comments in 2136 // Add reference on behalf of FrameLoader. See comments in
2132 // WebFrameLoaderClient::frameLoaderDestroyed for more info. 2137 // WebFrameLoaderClient::frameLoaderDestroyed for more info.
2133 ref(); 2138 ref();
2134 2139
2135 // We must call init() after m_frame is assigned because it is referenced 2140 // We must call init() after m_frame is assigned because it is referenced
2136 // during init(). 2141 // during init().
2137 frame()->init(); 2142 frame()->init();
2138 } 2143 }
2139 2144
2140 PassRefPtr<Frame> WebFrameImpl::createChildFrame(const FrameLoadRequest& request , HTMLFrameOwnerElement* ownerElement) 2145 PassRefPtr<Frame> WebFrameImpl::createChildFrame(const FrameLoadRequest& request , HTMLFrameOwnerElement* ownerElement)
2141 { 2146 {
2142 RefPtr<WebFrameImpl> webframe(adoptRef(new WebFrameImpl(m_client))); 2147 RefPtr<WebFrameImpl> webframe(m_client ? adoptRef(static_cast<WebFrameImpl*> (m_client->didCreateFrame(request.frameName()))) : WebFrameImpl::create(0));
2143 2148
2144 // Add an extra ref on behalf of the Frame/FrameLoader, which references the 2149 // Add an extra ref on behalf of the Frame/FrameLoader, which references the
2145 // WebFrame via the FrameLoaderClient interface. See the comment at the top 2150 // WebFrame via the FrameLoaderClient interface. See the comment at the top
2146 // of this file for more info. 2151 // of this file for more info.
2147 webframe->ref(); 2152 webframe->ref();
2148 2153
2149 RefPtr<Frame> childFrame = Frame::create(frame()->page(), ownerElement, &web frame->m_frameLoaderClient); 2154 RefPtr<Frame> childFrame = Frame::create(frame()->page(), ownerElement, &web frame->m_frameLoaderClient);
2150 webframe->setWebCoreFrame(childFrame.get()); 2155 webframe->setWebCoreFrame(childFrame.get());
2151 2156
2152 childFrame->tree()->setName(request.frameName()); 2157 childFrame->tree()->setName(request.frameName());
2153 2158
2154 frame()->tree()->appendChild(childFrame); 2159 frame()->tree()->appendChild(childFrame);
2155 2160
2156 // Frame::init() can trigger onload event in the parent frame, 2161 // Frame::init() can trigger onload event in the parent frame,
2157 // which may detach this frame and trigger a null-pointer access 2162 // which may detach this frame and trigger a null-pointer access
2158 // in FrameTree::removeChild. Move init() after appendChild call 2163 // in FrameTree::removeChild. Move init() after appendChild call
2159 // so that webframe->mFrame is in the tree before triggering 2164 // so that webframe->mFrame is in the tree before triggering
2160 // onload event handler. 2165 // onload event handler.
2161 // Because the event handler may set webframe->mFrame to null, 2166 // Because the event handler may set webframe->mFrame to null,
2162 // it is necessary to check the value after calling init() and 2167 // it is necessary to check the value after calling init() and
2163 // return without loading URL. 2168 // return without loading URL.
2164 // (b:791612) 2169 // (b:791612)
2165 childFrame->init(); // create an empty document 2170 childFrame->init(); // create an empty document
2166 if (!childFrame->tree()->parent()) 2171 if (!childFrame->tree()->parent()) {
2172 if (m_client)
2173 m_client->frameDetached(webframe.get());
2167 return 0; 2174 return 0;
2175 }
2168 2176
2169 HistoryItem* parentItem = frame()->loader()->history()->currentItem(); 2177 HistoryItem* parentItem = frame()->loader()->history()->currentItem();
2170 HistoryItem* childItem = 0; 2178 HistoryItem* childItem = 0;
2171 // If we're moving in the back/forward list, we might want to replace the co ntent 2179 // If we're moving in the back/forward list, we might want to replace the co ntent
2172 // of this child frame with whatever was there at that point. 2180 // of this child frame with whatever was there at that point.
2173 if (parentItem && parentItem->children().size() && isBackForwardLoadType(fra me()->loader()->loadType()) && !frame()->document()->loadEventFinished()) 2181 if (parentItem && parentItem->children().size() && isBackForwardLoadType(fra me()->loader()->loadType()) && !frame()->document()->loadEventFinished())
2174 childItem = parentItem->childItemWithTarget(childFrame->tree()->uniqueNa me()); 2182 childItem = parentItem->childItemWithTarget(childFrame->tree()->uniqueNa me());
2175 2183
2176 if (childItem) 2184 if (childItem)
2177 childFrame->loader()->loadHistoryItem(childItem); 2185 childFrame->loader()->loadHistoryItem(childItem);
2178 else 2186 else
2179 childFrame->loader()->load(FrameLoadRequest(0, request.resourceRequest() , "_self")); 2187 childFrame->loader()->load(FrameLoadRequest(0, request.resourceRequest() , "_self"));
2180 2188
2181 // A synchronous navigation (about:blank) would have already processed 2189 // A synchronous navigation (about:blank) would have already processed
2182 // onload, so it is possible for the frame to have already been destroyed by 2190 // onload, so it is possible for the frame to have already been destroyed by
2183 // script in the page. 2191 // script in the page.
2184 if (!childFrame->tree()->parent()) 2192 if (!childFrame->tree()->parent()) {
2193 if (m_client)
2194 m_client->frameDetached(webframe.get());
2185 return 0; 2195 return 0;
2196 }
2186 2197
2187 if (m_client)
2188 m_client->didCreateFrame(this, webframe.get());
2189 2198
2190 return childFrame.release(); 2199 return childFrame.release();
2191 } 2200 }
2192 2201
2193 void WebFrameImpl::didChangeContentsSize(const IntSize& size) 2202 void WebFrameImpl::didChangeContentsSize(const IntSize& size)
2194 { 2203 {
2195 // This is only possible on the main frame. 2204 // This is only possible on the main frame.
2196 if (m_totalMatchCount > 0) { 2205 if (m_totalMatchCount > 0) {
2197 ASSERT(!parent()); 2206 ASSERT(!parent());
2198 ++m_findMatchMarkersVersion; 2207 ++m_findMatchMarkersVersion;
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
2483 2492
2484 // There is a possibility that the frame being detached was the only 2493 // There is a possibility that the frame being detached was the only
2485 // pending one. We need to make sure final replies can be sent. 2494 // pending one. We need to make sure final replies can be sent.
2486 flushCurrentScopingEffort(m_findRequestIdentifier); 2495 flushCurrentScopingEffort(m_findRequestIdentifier);
2487 2496
2488 cancelPendingScopingEffort(); 2497 cancelPendingScopingEffort();
2489 } 2498 }
2490 } 2499 }
2491 2500
2492 } // namespace WebKit 2501 } // namespace WebKit
OLDNEW
« no previous file with comments | « no previous file | Source/web/tests/WebFrameTest.cpp » ('j') | public/web/WebFrameClient.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698