Chromium Code Reviews| OLD | NEW |
|---|---|
| 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; | |
| 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 Loading... | |
| 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 || !renderWidget->isWidget()) | |
|
eseidel
2013/12/12 20:40:13
What does isWidget() do here?
wjmaclean
2013/12/12 22:31:15
I'm not entirely sure, but even RenderWidget() was
| |
| 188 return; | |
| 189 | |
| 190 if (m_widget) { | |
| 191 if (renderWidget->style()) { | |
|
eseidel
2013/12/12 20:40:13
It feels liek this wants to call some method on th
wjmaclean
2013/12/12 22:31:15
OK.
| |
| 192 if (!renderWidget->needsLayout()) | |
| 193 renderWidget->updateWidgetGeometry(); | |
| 194 | |
| 195 if (renderWidget->style()->visibility() != VISIBLE) { | |
|
eseidel
2013/12/12 20:40:13
This all seems suspect. The DOM shouldn't be deal
wjmaclean
2013/12/12 22:31:15
Is it ok if dealt with as described above? Or do w
| |
| 196 m_widget->hide(); | |
| 197 } else { | |
| 198 m_widget->show(); | |
| 199 renderWidget->repaint(); | |
| 200 } | |
| 201 } | |
| 202 ASSERT(document().view() == renderWidget->frameView()); | |
| 203 ASSERT(renderWidget->frameView()); | |
| 204 moveWidgetToParentSoon(m_widget.get(), renderWidget->frameView()); | |
| 205 } | |
| 206 | |
| 207 if (AXObjectCache* cache = document().existingAXObjectCache()) | |
| 208 cache->childrenChanged(renderWidget); | |
| 209 | |
| 210 if (RenderPart* renderPart = toRenderPart(renderWidget)) | |
| 211 renderPart->viewCleared(); | |
| 212 } | |
| 213 | |
| 214 Widget* HTMLFrameOwnerElement::widget() const | |
| 215 { | |
| 216 return m_widget.get(); | |
| 217 } | |
| 218 | |
| 124 bool HTMLFrameOwnerElement::loadOrRedirectSubframe(const KURL& url, const Atomic String& frameName, bool lockBackForwardList) | 219 bool HTMLFrameOwnerElement::loadOrRedirectSubframe(const KURL& url, const Atomic String& frameName, bool lockBackForwardList) |
| 125 { | 220 { |
| 126 RefPtr<Frame> parentFrame = document().frame(); | 221 RefPtr<Frame> parentFrame = document().frame(); |
| 127 if (contentFrame()) { | 222 if (contentFrame()) { |
| 128 contentFrame()->navigationScheduler().scheduleLocationChange(document(). securityOrigin(), url.string(), parentFrame->loader().outgoingReferrer(), lockBa ckForwardList); | 223 contentFrame()->navigationScheduler().scheduleLocationChange(document(). securityOrigin(), url.string(), parentFrame->loader().outgoingReferrer(), lockBa ckForwardList); |
| 129 return true; | 224 return true; |
| 130 } | 225 } |
| 131 | 226 |
| 132 if (!document().securityOrigin()->canDisplay(url)) { | 227 if (!document().securityOrigin()->canDisplay(url)) { |
| 133 FrameLoader::reportLocalLoadFailed(parentFrame.get(), url.string()); | 228 FrameLoader::reportLocalLoadFailed(parentFrame.get(), url.string()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 146 } | 241 } |
| 147 | 242 |
| 148 // All new frames will have m_isComplete set to true at this point due to sy nchronously loading | 243 // 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 | 244 // 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 | 245 // 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 | 246 // 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.) | 247 // 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. | 248 // FIXME: Can we remove this entirely? m_isComplete normally gets set to fal se when a load is committed. |
| 154 childFrame->loader().started(); | 249 childFrame->loader().started(); |
| 155 | 250 |
| 251 FrameView* view = childFrame->view(); | |
| 156 RenderObject* renderObject = renderer(); | 252 RenderObject* renderObject = renderer(); |
| 157 FrameView* view = childFrame->view(); | 253 // We need to test the existence of renderObject and its widget-ness, as |
| 254 // failing to do so causes problems. | |
| 158 if (renderObject && renderObject->isWidget() && view) | 255 if (renderObject && renderObject->isWidget() && view) |
| 159 toRenderWidget(renderObject)->setWidget(view); | 256 setWidget(view); |
| 160 | 257 |
| 161 // Some loads are performed synchronously (e.g., about:blank and loads | 258 // Some loads are performed synchronously (e.g., about:blank and loads |
| 162 // cancelled by returning a null ResourceRequest from requestFromDelegate). | 259 // cancelled by returning a null ResourceRequest from requestFromDelegate). |
| 163 // In these cases, the synchronous load would have finished | 260 // In these cases, the synchronous load would have finished |
| 164 // before we could connect the signals, so make sure to send the | 261 // 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 | 262 // completed() signal for the child by hand and mark the load as being |
| 166 // complete. | 263 // complete. |
| 167 // FIXME: In this case the Frame will have finished loading before | 264 // 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 | 265 // 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. | 266 // create the child first, then invoke the loader separately. |
| 170 if (childFrame->loader().state() == FrameStateComplete && !childFrame->loade r().policyDocumentLoader()) | 267 if (childFrame->loader().state() == FrameStateComplete && !childFrame->loade r().policyDocumentLoader()) |
| 171 childFrame->loader().checkCompleted(); | 268 childFrame->loader().checkCompleted(); |
| 172 return true; | 269 return true; |
| 173 } | 270 } |
| 174 | 271 |
| 175 | 272 |
| 176 } // namespace WebCore | 273 } // namespace WebCore |
| OLD | NEW |