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

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: Add WebViewHelper for unittests. 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
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
64 // in FrameLoader::detachFromParent for each subframe. 64 // in FrameLoader::detachFromParent for each subframe.
65 // 65 //
66 // Frame going away causes the FrameLoader to get deleted. In FrameLoader's 66 // Frame going away causes the FrameLoader to get deleted. In FrameLoader's
67 // destructor, it notifies its client with frameLoaderDestroyed. This calls 67 // destructor, it notifies its client with frameLoaderDestroyed. This derefs
68 // WebFrame::Closing and then derefs the WebFrame and will cause it to be 68 // the WebFrame and will cause it to be deleted (unless an external someone
69 // deleted (unless an external someone is also holding a reference). 69 // is also holding a reference).
70 //
71 // Thie client is expected to be set whenever the WebFrameImpl is attached to
72 // the DOM.
70 73
71 #include "config.h" 74 #include "config.h"
72 #include "WebFrameImpl.h" 75 #include "WebFrameImpl.h"
73 76
74 #include "AssociatedURLLoader.h" 77 #include "AssociatedURLLoader.h"
75 #include "DOMUtilitiesPrivate.h" 78 #include "DOMUtilitiesPrivate.h"
76 #include "EventListenerWrapper.h" 79 #include "EventListenerWrapper.h"
77 #include "FindInPageCoordinates.h" 80 #include "FindInPageCoordinates.h"
78 #include "HTMLNames.h" 81 #include "HTMLNames.h"
79 #include "PageOverlay.h" 82 #include "PageOverlay.h"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 if (output.length() >= maxChars - frameSeparatorLength) 262 if (output.length() >= maxChars - frameSeparatorLength)
260 return; 263 return;
261 264
262 output.append(frameSeparator, frameSeparatorLength); 265 output.append(frameSeparator, frameSeparatorLength);
263 frameContentAsPlainText(maxChars, curChild, output); 266 frameContentAsPlainText(maxChars, curChild, output);
264 if (output.length() >= maxChars) 267 if (output.length() >= maxChars)
265 return; // Filled up the buffer. 268 return; // Filled up the buffer.
266 } 269 }
267 } 270 }
268 271
269 static long long generateFrameIdentifier()
270 {
271 static long long next = 0;
272 return ++next;
273 }
274
275 WebPluginContainerImpl* WebFrameImpl::pluginContainerFromFrame(Frame* frame) 272 WebPluginContainerImpl* WebFrameImpl::pluginContainerFromFrame(Frame* frame)
276 { 273 {
277 if (!frame) 274 if (!frame)
278 return 0; 275 return 0;
279 if (!frame->document() || !frame->document()->isPluginDocument()) 276 if (!frame->document() || !frame->document()->isPluginDocument())
280 return 0; 277 return 0;
281 PluginDocument* pluginDocument = static_cast<PluginDocument*>(frame->documen t()); 278 PluginDocument* pluginDocument = static_cast<PluginDocument*>(frame->documen t());
282 return toPluginContainerImpl(pluginDocument->pluginWidget()); 279 return toPluginContainerImpl(pluginDocument->pluginWidget());
283 } 280 }
284 281
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 WebFrame* WebFrame::frameForContext(v8::Handle<v8::Context> context) 526 WebFrame* WebFrame::frameForContext(v8::Handle<v8::Context> context)
530 { 527 {
531 return WebFrameImpl::fromFrame(toFrameIfNotDetached(context)); 528 return WebFrameImpl::fromFrame(toFrameIfNotDetached(context));
532 } 529 }
533 530
534 WebFrame* WebFrame::fromFrameOwnerElement(const WebElement& element) 531 WebFrame* WebFrame::fromFrameOwnerElement(const WebElement& element)
535 { 532 {
536 return WebFrameImpl::fromFrameOwnerElement(PassRefPtr<Element>(element).get( )); 533 return WebFrameImpl::fromFrameOwnerElement(PassRefPtr<Element>(element).get( ));
537 } 534 }
538 535
536 void WebFrameImpl::close()
darin (slow to review) 2013/09/13 04:02:47 not that you should clean this up now, but WebFram
537 {
538 m_client = 0;
539 deref(); // Balances ref() acquired in WebFrame::create
darin (slow to review) 2013/09/13 04:02:47 nit: WebFrameImpl::create
540 }
darin (slow to review) 2013/09/13 04:02:47 you might want to add a comment here explaining wh
541
539 WebString WebFrameImpl::uniqueName() const 542 WebString WebFrameImpl::uniqueName() const
540 { 543 {
541 return frame()->tree()->uniqueName(); 544 return frame()->tree()->uniqueName();
542 } 545 }
543 546
544 WebString WebFrameImpl::assignedName() const 547 WebString WebFrameImpl::assignedName() const
545 { 548 {
546 return frame()->tree()->name(); 549 return frame()->tree()->name();
547 } 550 }
548 551
(...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 WebString WebFrameImpl::layerTreeAsText(bool showDebugInfo) const 2069 WebString WebFrameImpl::layerTreeAsText(bool showDebugInfo) const
2067 { 2070 {
2068 if (!frame()) 2071 if (!frame())
2069 return WebString(); 2072 return WebString();
2070 2073
2071 return WebString(frame()->layerTreeAsText(showDebugInfo ? LayerTreeIncludesD ebugInfo : LayerTreeNormal)); 2074 return WebString(frame()->layerTreeAsText(showDebugInfo ? LayerTreeIncludesD ebugInfo : LayerTreeNormal));
2072 } 2075 }
2073 2076
2074 // WebFrameImpl public --------------------------------------------------------- 2077 // WebFrameImpl public ---------------------------------------------------------
2075 2078
2076 PassRefPtr<WebFrameImpl> WebFrameImpl::create(WebFrameClient* client) 2079 WebFrame* WebFrame::create(WebFrameClient* client)
2077 { 2080 {
2078 return adoptRef(new WebFrameImpl(client)); 2081 return WebFrameImpl::create(client, generateFrameIdentifier());
2079 } 2082 }
2080 2083
2081 WebFrameImpl::WebFrameImpl(WebFrameClient* client) 2084 WebFrame* WebFrame::create(WebFrameClient* client, long long identifier)
2085 {
2086 return WebFrameImpl::create(client, identifier);
2087 }
2088
2089 long long WebFrame::generateFrameIdentifier()
2090 {
2091 static long long next = 0;
2092 // Assume that 64-bit will not wrap to -1.
2093 return ++next;
2094 }
2095
2096 WebFrameImpl* WebFrameImpl::create(WebFrameClient* client, long long identifier)
2097 {
2098 return adoptRef(new WebFrameImpl(client, identifier)).leakRef();
darin (slow to review) 2013/09/13 04:02:47 nit: add a comment indicating that this leak gets
2099 }
2100
2101 WebFrameImpl::WebFrameImpl(WebFrameClient* client, long long identifier)
2082 : FrameDestructionObserver(0) 2102 : FrameDestructionObserver(0)
2083 , m_frameLoaderClient(this) 2103 , m_frameLoaderClient(this)
2084 , m_client(client) 2104 , m_client(client)
2085 , m_currentActiveMatchFrame(0) 2105 , m_currentActiveMatchFrame(0)
2086 , m_activeMatchIndexInCurrentFrame(-1) 2106 , m_activeMatchIndexInCurrentFrame(-1)
2087 , m_locatingActiveRect(false) 2107 , m_locatingActiveRect(false)
2088 , m_resumeScopingFromRange(0) 2108 , m_resumeScopingFromRange(0)
2089 , m_lastMatchCount(-1) 2109 , m_lastMatchCount(-1)
2090 , m_totalMatchCount(-1) 2110 , m_totalMatchCount(-1)
2091 , m_framesScopingCount(-1) 2111 , m_framesScopingCount(-1)
2092 , m_findRequestIdentifier(-1) 2112 , m_findRequestIdentifier(-1)
2093 , m_scopingInProgress(false) 2113 , m_scopingInProgress(false)
2094 , m_lastFindRequestCompletedWithNoMatches(false) 2114 , m_lastFindRequestCompletedWithNoMatches(false)
2095 , m_nextInvalidateAfter(0) 2115 , m_nextInvalidateAfter(0)
2096 , m_findMatchMarkersVersion(0) 2116 , m_findMatchMarkersVersion(0)
2097 , m_findMatchRectsAreValid(false) 2117 , m_findMatchRectsAreValid(false)
2098 , m_identifier(generateFrameIdentifier()) 2118 , m_identifier(identifier)
darin (slow to review) 2013/09/13 04:02:47 We should just move the concept of WebFrame identi
awong 2013/09/13 04:25:02 I did this initially, but didn't know how to handl
2099 , m_inSameDocumentHistoryLoad(false) 2119 , m_inSameDocumentHistoryLoad(false)
2100 { 2120 {
2101 WebKit::Platform::current()->incrementStatsCounter(webFrameActiveCount); 2121 WebKit::Platform::current()->incrementStatsCounter(webFrameActiveCount);
2102 frameCount++; 2122 frameCount++;
2103 } 2123 }
2104 2124
2105 WebFrameImpl::~WebFrameImpl() 2125 WebFrameImpl::~WebFrameImpl()
2106 { 2126 {
2107 WebKit::Platform::current()->decrementStatsCounter(webFrameActiveCount); 2127 WebKit::Platform::current()->decrementStatsCounter(webFrameActiveCount);
2108 frameCount--; 2128 frameCount--;
2109 2129
2110 cancelPendingScopingEffort(); 2130 cancelPendingScopingEffort();
2111 } 2131 }
2112 2132
2113 void WebFrameImpl::setWebCoreFrame(WebCore::Frame* frame) 2133 void WebFrameImpl::setWebCoreFrame(WebCore::Frame* frame)
2114 { 2134 {
2115 ASSERT(frame); 2135 ASSERT(frame);
2116 observeFrame(frame); 2136 observeFrame(frame);
2117 } 2137 }
2118 2138
2119 void WebFrameImpl::initializeAsMainFrame(WebCore::Page* page) 2139 void WebFrameImpl::initializeAsMainFrame(WebCore::Page* page)
2120 { 2140 {
2121 RefPtr<Frame> mainFrame = Frame::create(page, 0, &m_frameLoaderClient); 2141 RefPtr<Frame> mainFrame = Frame::create(page, 0, &m_frameLoaderClient);
2122 setWebCoreFrame(mainFrame.get()); 2142 setWebCoreFrame(mainFrame.get());
2123 2143
2124 // Add reference on behalf of FrameLoader. See comments in 2144 // Add reference on behalf of FrameLoader. See comments in
2125 // WebFrameLoaderClient::frameLoaderDestroyed for more info. 2145 // WebFrameLoaderClient::frameLoaderDestroyed for more info.
2126 ref(); 2146 ref();
2127 2147
2128 // We must call init() after m_frame is assigned because it is referenced 2148 // We must call init() after m_frame is assigned because it is referenced
2129 // during init(). 2149 // during init().
2130 frame()->init(); 2150 frame()->init();
2131 } 2151 }
2132 2152
2133 PassRefPtr<Frame> WebFrameImpl::createChildFrame(const FrameLoadRequest& request , HTMLFrameOwnerElement* ownerElement) 2153 PassRefPtr<Frame> WebFrameImpl::createChildFrame(const FrameLoadRequest& request , HTMLFrameOwnerElement* ownerElement)
2134 { 2154 {
2135 RefPtr<WebFrameImpl> webframe(adoptRef(new WebFrameImpl(m_client))); 2155 ASSERT(m_client);
2156 WebFrameImpl* webframe = static_cast<WebFrameImpl*>(m_client->createChildFra me(this, request.frameName()));
2136 2157
2137 // Add an extra ref on behalf of the Frame/FrameLoader, which references the 2158 // Add an extra ref on behalf of the Frame/FrameLoader, which references the
2138 // WebFrame via the FrameLoaderClient interface. See the comment at the top 2159 // WebFrame via the FrameLoaderClient interface. See the comment at the top
2139 // of this file for more info. 2160 // of this file for more info.
2140 webframe->ref(); 2161 webframe->ref();
2141 2162
2142 RefPtr<Frame> childFrame = Frame::create(frame()->page(), ownerElement, &web frame->m_frameLoaderClient); 2163 RefPtr<Frame> childFrame = Frame::create(frame()->page(), ownerElement, &web frame->m_frameLoaderClient);
2143 webframe->setWebCoreFrame(childFrame.get()); 2164 webframe->setWebCoreFrame(childFrame.get());
2144 2165
2145 childFrame->tree()->setName(request.frameName()); 2166 childFrame->tree()->setName(request.frameName());
2146 2167
2147 frame()->tree()->appendChild(childFrame); 2168 frame()->tree()->appendChild(childFrame);
2148 2169
2149 // Frame::init() can trigger onload event in the parent frame, 2170 // Frame::init() can trigger onload event in the parent frame,
2150 // which may detach this frame and trigger a null-pointer access 2171 // which may detach this frame and trigger a null-pointer access
2151 // in FrameTree::removeChild. Move init() after appendChild call 2172 // in FrameTree::removeChild. Move init() after appendChild call
2152 // so that webframe->mFrame is in the tree before triggering 2173 // so that webframe->mFrame is in the tree before triggering
2153 // onload event handler. 2174 // onload event handler.
2154 // Because the event handler may set webframe->mFrame to null, 2175 // Because the event handler may set webframe->mFrame to null,
2155 // it is necessary to check the value after calling init() and 2176 // it is necessary to check the value after calling init() and
2156 // return without loading URL. 2177 // return without loading URL.
2157 // (b:791612) 2178 // (b:791612)
2158 childFrame->init(); // create an empty document 2179 childFrame->init(); // create an empty document
2159 if (!childFrame->tree()->parent()) 2180 if (!childFrame->tree()->parent()) {
2181 if (m_client)
2182 m_client->frameDetached(webframe);
darin (slow to review) 2013/09/13 04:02:47 there have been bugs where it appeared from the ch
2160 return 0; 2183 return 0;
2184 }
2161 2185
2162 HistoryItem* parentItem = frame()->loader()->history()->currentItem(); 2186 HistoryItem* parentItem = frame()->loader()->history()->currentItem();
2163 HistoryItem* childItem = 0; 2187 HistoryItem* childItem = 0;
2164 // If we're moving in the back/forward list, we might want to replace the co ntent 2188 // If we're moving in the back/forward list, we might want to replace the co ntent
2165 // of this child frame with whatever was there at that point. 2189 // of this child frame with whatever was there at that point.
2166 if (parentItem && parentItem->children().size() && isBackForwardLoadType(fra me()->loader()->loadType()) && !frame()->document()->loadEventFinished()) 2190 if (parentItem && parentItem->children().size() && isBackForwardLoadType(fra me()->loader()->loadType()) && !frame()->document()->loadEventFinished())
2167 childItem = parentItem->childItemWithTarget(childFrame->tree()->uniqueNa me()); 2191 childItem = parentItem->childItemWithTarget(childFrame->tree()->uniqueNa me());
2168 2192
2169 if (childItem) 2193 if (childItem)
2170 childFrame->loader()->loadHistoryItem(childItem); 2194 childFrame->loader()->loadHistoryItem(childItem);
2171 else 2195 else
2172 childFrame->loader()->load(FrameLoadRequest(0, request.resourceRequest() , "_self")); 2196 childFrame->loader()->load(FrameLoadRequest(0, request.resourceRequest() , "_self"));
2173 2197
2174 // A synchronous navigation (about:blank) would have already processed 2198 // A synchronous navigation (about:blank) would have already processed
2175 // onload, so it is possible for the frame to have already been destroyed by 2199 // onload, so it is possible for the frame to have already been destroyed by
2176 // script in the page. 2200 // script in the page.
2177 if (!childFrame->tree()->parent()) 2201 if (!childFrame->tree()->parent()) {
2202 if (m_client)
2203 m_client->frameDetached(webframe);
2178 return 0; 2204 return 0;
2205 }
2179 2206
2180 if (m_client)
2181 m_client->didCreateFrame(this, webframe.get());
2182 2207
2183 return childFrame.release(); 2208 return childFrame.release();
2184 } 2209 }
2185 2210
2186 void WebFrameImpl::didChangeContentsSize(const IntSize& size) 2211 void WebFrameImpl::didChangeContentsSize(const IntSize& size)
2187 { 2212 {
2188 // This is only possible on the main frame. 2213 // This is only possible on the main frame.
2189 if (m_totalMatchCount > 0) { 2214 if (m_totalMatchCount > 0) {
2190 ASSERT(!parent()); 2215 ASSERT(!parent());
2191 ++m_findMatchMarkersVersion; 2216 ++m_findMatchMarkersVersion;
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
2476 2501
2477 // There is a possibility that the frame being detached was the only 2502 // There is a possibility that the frame being detached was the only
2478 // pending one. We need to make sure final replies can be sent. 2503 // pending one. We need to make sure final replies can be sent.
2479 flushCurrentScopingEffort(m_findRequestIdentifier); 2504 flushCurrentScopingEffort(m_findRequestIdentifier);
2480 2505
2481 cancelPendingScopingEffort(); 2506 cancelPendingScopingEffort();
2482 } 2507 }
2483 } 2508 }
2484 2509
2485 } // namespace WebKit 2510 } // namespace WebKit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698