| 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 void HTMLFrameOwnerElement::UpdateSuspendScope::performDeferredWidgetTreeOperati
ons() |
| 54 { |
| 55 WidgetToParentMap map; |
| 56 widgetNewParentMap().swap(map); |
| 57 WidgetToParentMap::iterator end = map.end(); |
| 58 for (WidgetToParentMap::iterator it = map.begin(); it != end; ++it) { |
| 59 Widget* child = it->key.get(); |
| 60 ScrollView* currentParent = toScrollView(child->parent()); |
| 61 FrameView* newParent = it->value; |
| 62 if (newParent != currentParent) { |
| 63 if (currentParent) |
| 64 currentParent->removeChild(child); |
| 65 if (newParent) |
| 66 newParent->addChild(child); |
| 67 } |
| 68 } |
| 69 } |
| 70 |
| 71 HTMLFrameOwnerElement::UpdateSuspendScope::~UpdateSuspendScope() |
| 72 { |
| 73 ASSERT(s_updateSuspendCount > 0); |
| 74 if (s_updateSuspendCount == 1) |
| 75 performDeferredWidgetTreeOperations(); |
| 76 --s_updateSuspendCount; |
| 77 } |
| 78 |
| 79 static void moveWidgetToParentSoon(Widget* child, FrameView* parent) |
| 80 { |
| 81 if (!s_updateSuspendCount) { |
| 82 if (parent) |
| 83 parent->addChild(child); |
| 84 else if (toScrollView(child->parent())) |
| 85 toScrollView(child->parent())->removeChild(child); |
| 86 return; |
| 87 } |
| 88 widgetNewParentMap().set(child, parent); |
| 89 } |
| 90 |
| 38 HTMLFrameOwnerElement::HTMLFrameOwnerElement(const QualifiedName& tagName, Docum
ent& document) | 91 HTMLFrameOwnerElement::HTMLFrameOwnerElement(const QualifiedName& tagName, Docum
ent& document) |
| 39 : HTMLElement(tagName, document) | 92 : HTMLElement(tagName, document) |
| 40 , m_contentFrame(0) | 93 , m_contentFrame(0) |
| 41 , m_sandboxFlags(SandboxNone) | 94 , m_sandboxFlags(SandboxNone) |
| 42 { | 95 { |
| 43 } | 96 } |
| 44 | 97 |
| 45 RenderPart* HTMLFrameOwnerElement::renderPart() const | 98 RenderPart* HTMLFrameOwnerElement::renderPart() const |
| 46 { | 99 { |
| 47 // HTMLObjectElement and HTMLEmbedElement may return arbitrary renderers | 100 // HTMLObjectElement and HTMLEmbedElement may return arbitrary renderers |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 167 } |
| 115 | 168 |
| 116 SVGDocument* HTMLFrameOwnerElement::getSVGDocument(ExceptionState& exceptionStat
e) const | 169 SVGDocument* HTMLFrameOwnerElement::getSVGDocument(ExceptionState& exceptionStat
e) const |
| 117 { | 170 { |
| 118 Document* doc = contentDocument(); | 171 Document* doc = contentDocument(); |
| 119 if (doc && doc->isSVGDocument()) | 172 if (doc && doc->isSVGDocument()) |
| 120 return toSVGDocument(doc); | 173 return toSVGDocument(doc); |
| 121 return 0; | 174 return 0; |
| 122 } | 175 } |
| 123 | 176 |
| 177 void HTMLFrameOwnerElement::setWidget(PassRefPtr<Widget> widget) |
| 178 { |
| 179 if (widget == m_widget) |
| 180 return; |
| 181 |
| 182 if (m_widget) { |
| 183 if (m_widget->parent()) |
| 184 moveWidgetToParentSoon(m_widget.get(), 0); |
| 185 m_widget = 0; |
| 186 } |
| 187 |
| 188 m_widget = widget; |
| 189 |
| 190 RenderWidget* renderWidget = toRenderWidget(renderer()); |
| 191 if (!renderWidget) |
| 192 return; |
| 193 |
| 194 if (m_widget) { |
| 195 renderWidget->updateOnWidgetChange(); |
| 196 |
| 197 ASSERT(document().view() == renderWidget->frameView()); |
| 198 ASSERT(renderWidget->frameView()); |
| 199 moveWidgetToParentSoon(m_widget.get(), renderWidget->frameView()); |
| 200 } |
| 201 |
| 202 if (AXObjectCache* cache = document().existingAXObjectCache()) |
| 203 cache->childrenChanged(renderWidget); |
| 204 |
| 205 if (RenderPart* renderPart = toRenderPart(renderWidget)) |
| 206 renderPart->viewCleared(); |
| 207 } |
| 208 |
| 209 Widget* HTMLFrameOwnerElement::widget() const |
| 210 { |
| 211 return m_widget.get(); |
| 212 } |
| 213 |
| 124 bool HTMLFrameOwnerElement::loadOrRedirectSubframe(const KURL& url, const Atomic
String& frameName, bool lockBackForwardList) | 214 bool HTMLFrameOwnerElement::loadOrRedirectSubframe(const KURL& url, const Atomic
String& frameName, bool lockBackForwardList) |
| 125 { | 215 { |
| 126 RefPtr<Frame> parentFrame = document().frame(); | 216 RefPtr<Frame> parentFrame = document().frame(); |
| 127 if (contentFrame()) { | 217 if (contentFrame()) { |
| 128 contentFrame()->navigationScheduler().scheduleLocationChange(&document()
, url.string(), document().outgoingReferrer(), lockBackForwardList); | 218 contentFrame()->navigationScheduler().scheduleLocationChange(&document()
, url.string(), document().outgoingReferrer(), lockBackForwardList); |
| 129 return true; | 219 return true; |
| 130 } | 220 } |
| 131 | 221 |
| 132 if (!document().securityOrigin()->canDisplay(url)) { | 222 if (!document().securityOrigin()->canDisplay(url)) { |
| 133 FrameLoader::reportLocalLoadFailed(parentFrame.get(), url.string()); | 223 FrameLoader::reportLocalLoadFailed(parentFrame.get(), url.string()); |
| 134 return false; | 224 return false; |
| 135 } | 225 } |
| 136 | 226 |
| 137 if (!SubframeLoadingDisabler::canLoadFrame(*this)) | 227 if (!SubframeLoadingDisabler::canLoadFrame(*this)) |
| 138 return false; | 228 return false; |
| 139 | 229 |
| 140 String referrer = SecurityPolicy::generateReferrerHeader(document().referrer
Policy(), url, document().outgoingReferrer()); | 230 String referrer = SecurityPolicy::generateReferrerHeader(document().referrer
Policy(), url, document().outgoingReferrer()); |
| 231 |
| 141 RefPtr<Frame> childFrame = parentFrame->loader().client()->createFrame(url,
frameName, referrer, this); | 232 RefPtr<Frame> childFrame = parentFrame->loader().client()->createFrame(url,
frameName, referrer, this); |
| 142 | 233 |
| 143 if (!childFrame) { | 234 if (!childFrame) { |
| 144 parentFrame->loader().checkCompleted(); | 235 parentFrame->loader().checkCompleted(); |
| 145 return false; | 236 return false; |
| 146 } | 237 } |
| 147 | 238 |
| 148 // All new frames will have m_isComplete set to true at this point due to sy
nchronously loading | 239 // 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 | 240 // 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 | 241 // 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 | 242 // 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.) | 243 // 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. | 244 // FIXME: Can we remove this entirely? m_isComplete normally gets set to fal
se when a load is committed. |
| 154 childFrame->loader().started(); | 245 childFrame->loader().started(); |
| 155 | 246 |
| 247 FrameView* view = childFrame->view(); |
| 156 RenderObject* renderObject = renderer(); | 248 RenderObject* renderObject = renderer(); |
| 157 FrameView* view = childFrame->view(); | 249 // We need to test the existence of renderObject and its widget-ness, as |
| 250 // failing to do so causes problems. |
| 158 if (renderObject && renderObject->isWidget() && view) | 251 if (renderObject && renderObject->isWidget() && view) |
| 159 toRenderWidget(renderObject)->setWidget(view); | 252 setWidget(view); |
| 160 | 253 |
| 161 // Some loads are performed synchronously (e.g., about:blank and loads | 254 // Some loads are performed synchronously (e.g., about:blank and loads |
| 162 // cancelled by returning a null ResourceRequest from requestFromDelegate). | 255 // cancelled by returning a null ResourceRequest from requestFromDelegate). |
| 163 // In these cases, the synchronous load would have finished | 256 // In these cases, the synchronous load would have finished |
| 164 // before we could connect the signals, so make sure to send the | 257 // 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 | 258 // completed() signal for the child by hand and mark the load as being |
| 166 // complete. | 259 // complete. |
| 167 // FIXME: In this case the Frame will have finished loading before | 260 // 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 | 261 // 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. | 262 // create the child first, then invoke the loader separately. |
| 170 if (childFrame->loader().state() == FrameStateComplete && !childFrame->loade
r().policyDocumentLoader()) | 263 if (childFrame->loader().state() == FrameStateComplete && !childFrame->loade
r().policyDocumentLoader()) |
| 171 childFrame->loader().checkCompleted(); | 264 childFrame->loader().checkCompleted(); |
| 172 return true; | 265 return true; |
| 173 } | 266 } |
| 174 | 267 |
| 175 | 268 |
| 176 } // namespace WebCore | 269 } // namespace WebCore |
| OLD | NEW |