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

Side by Side Diff: Source/core/html/HTMLFrameOwnerElement.cpp

Issue 23618022: BrowserPlugin/WebView - Move plugin lifetime to DOM (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix mac compile issue. Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 * 18 *
19 */ 19 */
20 20
21 #include "config.h" 21 #include "config.h"
22 #include "core/html/HTMLFrameOwnerElement.h" 22 #include "core/html/HTMLFrameOwnerElement.h"
23 23
24 #include "bindings/v8/ExceptionMessages.h" 24 #include "bindings/v8/ExceptionMessages.h"
25 #include "bindings/v8/ExceptionState.h" 25 #include "bindings/v8/ExceptionState.h"
26 #include "core/accessibility/AXObjectCache.h"
26 #include "core/dom/ExceptionCode.h" 27 #include "core/dom/ExceptionCode.h"
27 #include "core/loader/FrameLoader.h" 28 #include "core/loader/FrameLoader.h"
28 #include "core/loader/FrameLoaderClient.h" 29 #include "core/loader/FrameLoaderClient.h"
29 #include "core/frame/Frame.h" 30 #include "core/frame/Frame.h"
30 #include "core/frame/FrameView.h" 31 #include "core/frame/FrameView.h"
31 #include "core/rendering/RenderPart.h" 32 #include "core/rendering/RenderPart.h"
32 #include "core/svg/SVGDocument.h" 33 #include "core/svg/SVGDocument.h"
33 #include "platform/weborigin/SecurityOrigin.h" 34 #include "platform/weborigin/SecurityOrigin.h"
34 #include "platform/weborigin/SecurityPolicy.h" 35 #include "platform/weborigin/SecurityPolicy.h"
35 36
36 namespace WebCore { 37 namespace WebCore {
37 38
39 typedef HashMap<RefPtr<Widget>, FrameView*> WidgetToParentMap;
40 static WidgetToParentMap& widgetNewParentMap()
41 {
42 DEFINE_STATIC_LOCAL(WidgetToParentMap, map, ());
43 return map;
44 }
45
46 static unsigned s_updateSuspendCount = 0;
47
48 HTMLFrameOwnerElement::UpdateSuspendScope::UpdateSuspendScope()
49 {
50 ++s_updateSuspendCount;
51 }
52
53 HTMLFrameOwnerElement::UpdateSuspendScope::~UpdateSuspendScope()
54 {
55 ASSERT(s_updateSuspendCount > 0);
56 if (s_updateSuspendCount == 1) {
57 WidgetToParentMap map;
eseidel 2013/12/18 18:38:18 nit: I might have pushed this block into a helper
wjmaclean 2013/12/23 23:49:53 Done.
58 widgetNewParentMap().swap(map);
59 WidgetToParentMap::iterator end = map.end();
60 for (WidgetToParentMap::iterator it = map.begin(); it != end; ++it) {
61 Widget* child = it->key.get();
62 ScrollView* currentParent = toScrollView(child->parent());
63 FrameView* newParent = it->value;
64 if (newParent != currentParent) {
65 if (currentParent)
66 currentParent->removeChild(child);
67 if (newParent)
68 newParent->addChild(child);
69 }
70 }
71 }
72 --s_updateSuspendCount;
73 }
74
75 static void moveWidgetToParentSoon(Widget* child, FrameView* parent)
76 {
77 if (!s_updateSuspendCount) {
78 if (parent)
79 parent->addChild(child);
80 else if (toScrollView(child->parent()))
81 toScrollView(child->parent())->removeChild(child);
82 return;
83 }
84 widgetNewParentMap().set(child, parent);
85 }
86
38 HTMLFrameOwnerElement::HTMLFrameOwnerElement(const QualifiedName& tagName, Docum ent& document) 87 HTMLFrameOwnerElement::HTMLFrameOwnerElement(const QualifiedName& tagName, Docum ent& document)
39 : HTMLElement(tagName, document) 88 : HTMLElement(tagName, document)
40 , m_contentFrame(0) 89 , m_contentFrame(0)
41 , m_sandboxFlags(SandboxNone) 90 , m_sandboxFlags(SandboxNone)
42 { 91 {
43 } 92 }
44 93
45 RenderPart* HTMLFrameOwnerElement::renderPart() const 94 RenderPart* HTMLFrameOwnerElement::renderPart() const
46 { 95 {
47 // HTMLObjectElement and HTMLEmbedElement may return arbitrary renderers 96 // HTMLObjectElement and HTMLEmbedElement may return arbitrary renderers
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 163 }
115 164
116 SVGDocument* HTMLFrameOwnerElement::getSVGDocument(ExceptionState& exceptionStat e) const 165 SVGDocument* HTMLFrameOwnerElement::getSVGDocument(ExceptionState& exceptionStat e) const
117 { 166 {
118 Document* doc = contentDocument(); 167 Document* doc = contentDocument();
119 if (doc && doc->isSVGDocument()) 168 if (doc && doc->isSVGDocument())
120 return toSVGDocument(doc); 169 return toSVGDocument(doc);
121 return 0; 170 return 0;
122 } 171 }
123 172
173 void HTMLFrameOwnerElement::setWidget(PassRefPtr<Widget> widget)
174 {
175 if (widget == m_widget)
176 return;
177
178 if (m_widget) {
179 if (m_widget->parent())
180 moveWidgetToParentSoon(m_widget.get(), 0);
181 m_widget = 0;
182 }
183
184 m_widget = widget;
185
186 RenderWidget* renderWidget = toRenderWidget(renderer());
187 if (!renderWidget)
188 return;
189
190 if (m_widget) {
191 renderWidget->updateOnWidgetChange();
192
193 ASSERT(document().view() == renderWidget->frameView());
194 ASSERT(renderWidget->frameView());
195 moveWidgetToParentSoon(m_widget.get(), renderWidget->frameView());
196 }
197
198 if (AXObjectCache* cache = document().existingAXObjectCache())
199 cache->childrenChanged(renderWidget);
200
201 if (RenderPart* renderPart = toRenderPart(renderWidget))
202 renderPart->viewCleared();
203 }
204
205 Widget* HTMLFrameOwnerElement::widget() const
206 {
207 return m_widget.get();
208 }
209
124 bool HTMLFrameOwnerElement::loadOrRedirectSubframe(const KURL& url, const Atomic String& frameName, bool lockBackForwardList) 210 bool HTMLFrameOwnerElement::loadOrRedirectSubframe(const KURL& url, const Atomic String& frameName, bool lockBackForwardList)
125 { 211 {
126 RefPtr<Frame> parentFrame = document().frame(); 212 RefPtr<Frame> parentFrame = document().frame();
127 if (contentFrame()) { 213 if (contentFrame()) {
128 contentFrame()->navigationScheduler().scheduleLocationChange(&document() , url.string(), document().outgoingReferrer(), lockBackForwardList); 214 contentFrame()->navigationScheduler().scheduleLocationChange(&document() , url.string(), document().outgoingReferrer(), lockBackForwardList);
129 return true; 215 return true;
130 } 216 }
131 217
132 if (!document().securityOrigin()->canDisplay(url)) { 218 if (!document().securityOrigin()->canDisplay(url)) {
133 FrameLoader::reportLocalLoadFailed(parentFrame.get(), url.string()); 219 FrameLoader::reportLocalLoadFailed(parentFrame.get(), url.string());
134 return false; 220 return false;
135 } 221 }
136 222
137 if (!SubframeLoadingDisabler::canLoadFrame(*this)) 223 if (!SubframeLoadingDisabler::canLoadFrame(*this))
138 return false; 224 return false;
139 225
140 String referrer = SecurityPolicy::generateReferrerHeader(document().referrer Policy(), url, document().outgoingReferrer()); 226 String referrer = SecurityPolicy::generateReferrerHeader(document().referrer Policy(), url, document().outgoingReferrer());
227
141 RefPtr<Frame> childFrame = parentFrame->loader().client()->createFrame(url, frameName, referrer, this); 228 RefPtr<Frame> childFrame = parentFrame->loader().client()->createFrame(url, frameName, referrer, this);
142 229
143 if (!childFrame) { 230 if (!childFrame) {
144 parentFrame->loader().checkCompleted(); 231 parentFrame->loader().checkCompleted();
145 return false; 232 return false;
146 } 233 }
147 234
148 // All new frames will have m_isComplete set to true at this point due to sy nchronously loading 235 // All new frames will have m_isComplete set to true at this point due to sy nchronously loading
149 // an empty document in FrameLoader::init(). But many frames will now be sta rting an 236 // an empty document in FrameLoader::init(). But many frames will now be sta rting an
150 // asynchronous load of url, so we set m_isComplete to false and then check if the load is 237 // asynchronous load of url, so we set m_isComplete to false and then check if the load is
151 // actually completed below. (Note that we set m_isComplete to false even fo r synchronous 238 // actually completed below. (Note that we set m_isComplete to false even fo r synchronous
152 // loads, so that checkCompleted() below won't bail early.) 239 // loads, so that checkCompleted() below won't bail early.)
153 // FIXME: Can we remove this entirely? m_isComplete normally gets set to fal se when a load is committed. 240 // FIXME: Can we remove this entirely? m_isComplete normally gets set to fal se when a load is committed.
154 childFrame->loader().started(); 241 childFrame->loader().started();
155 242
243 FrameView* view = childFrame->view();
156 RenderObject* renderObject = renderer(); 244 RenderObject* renderObject = renderer();
157 FrameView* view = childFrame->view(); 245 // We need to test the existence of renderObject and its widget-ness, as
246 // failing to do so causes problems.
158 if (renderObject && renderObject->isWidget() && view) 247 if (renderObject && renderObject->isWidget() && view)
159 toRenderWidget(renderObject)->setWidget(view); 248 setWidget(view);
160 249
161 // Some loads are performed synchronously (e.g., about:blank and loads 250 // Some loads are performed synchronously (e.g., about:blank and loads
162 // cancelled by returning a null ResourceRequest from requestFromDelegate). 251 // cancelled by returning a null ResourceRequest from requestFromDelegate).
163 // In these cases, the synchronous load would have finished 252 // In these cases, the synchronous load would have finished
164 // before we could connect the signals, so make sure to send the 253 // before we could connect the signals, so make sure to send the
165 // completed() signal for the child by hand and mark the load as being 254 // completed() signal for the child by hand and mark the load as being
166 // complete. 255 // complete.
167 // FIXME: In this case the Frame will have finished loading before 256 // FIXME: In this case the Frame will have finished loading before
168 // it's being added to the child list. It would be a good idea to 257 // it's being added to the child list. It would be a good idea to
169 // create the child first, then invoke the loader separately. 258 // create the child first, then invoke the loader separately.
170 if (childFrame->loader().state() == FrameStateComplete && !childFrame->loade r().policyDocumentLoader()) 259 if (childFrame->loader().state() == FrameStateComplete && !childFrame->loade r().policyDocumentLoader())
171 childFrame->loader().checkCompleted(); 260 childFrame->loader().checkCompleted();
172 return true; 261 return true;
173 } 262 }
174 263
175 264
176 } // namespace WebCore 265 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698