OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "public/web/WebFrame.h" | 5 #include "public/web/WebFrame.h" |
6 | 6 |
7 #include "bindings/core/v8/WindowProxyManager.h" | 7 #include "bindings/core/v8/WindowProxyManager.h" |
8 #include "core/HTMLNames.h" | 8 #include "core/HTMLNames.h" |
9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "web/OpenedFrameTracker.h" | 21 #include "web/OpenedFrameTracker.h" |
22 #include "web/RemoteFrameOwner.h" | 22 #include "web/RemoteFrameOwner.h" |
23 #include "web/WebLocalFrameImpl.h" | 23 #include "web/WebLocalFrameImpl.h" |
24 #include "web/WebRemoteFrameImpl.h" | 24 #include "web/WebRemoteFrameImpl.h" |
25 #include <algorithm> | 25 #include <algorithm> |
26 | 26 |
27 namespace blink { | 27 namespace blink { |
28 | 28 |
29 bool WebFrame::Swap(WebFrame* frame) { | 29 bool WebFrame::Swap(WebFrame* frame) { |
30 using std::swap; | 30 using std::swap; |
31 Frame* old_frame = ToImplBase()->GetFrame(); | 31 Frame* old_frame = ToCoreFrame(*this); |
32 if (!old_frame->IsAttached()) | 32 if (!old_frame->IsAttached()) |
33 return false; | 33 return false; |
34 | 34 |
35 // Unload the current Document in this frame: this calls unload handlers, | 35 // Unload the current Document in this frame: this calls unload handlers, |
36 // detaches child frames, etc. Since this runs script, make sure this frame | 36 // detaches child frames, etc. Since this runs script, make sure this frame |
37 // wasn't detached before continuing with the swap. | 37 // wasn't detached before continuing with the swap. |
38 // FIXME: There is no unit test for this condition, so one needs to be | 38 // FIXME: There is no unit test for this condition, so one needs to be |
39 // written. | 39 // written. |
40 if (!old_frame->PrepareForCommit()) | 40 if (!old_frame->PrepareForCommit()) |
41 return false; | 41 return false; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 // Although the Document in this frame is now unloaded, many resources | 79 // Although the Document in this frame is now unloaded, many resources |
80 // associated with the frame itself have not yet been freed yet. | 80 // associated with the frame itself have not yet been freed yet. |
81 old_frame->Detach(FrameDetachType::kSwap); | 81 old_frame->Detach(FrameDetachType::kSwap); |
82 | 82 |
83 // Clone the state of the current Frame into the one being swapped in. | 83 // Clone the state of the current Frame into the one being swapped in. |
84 // FIXME: This is a bit clunky; this results in pointless decrements and | 84 // FIXME: This is a bit clunky; this results in pointless decrements and |
85 // increments of connected subframes. | 85 // increments of connected subframes. |
86 if (frame->IsWebLocalFrame()) { | 86 if (frame->IsWebLocalFrame()) { |
87 // TODO(dcheng): in an ideal world, both branches would just use | 87 // TODO(dcheng): in an ideal world, both branches would just use |
88 // WebFrameImplBase's initializeCoreFrame() helper. However, Blink | 88 // WebFrame's initializeCoreFrame() helper. However, Blink |
89 // currently requires a 'provisional' local frame to serve as a | 89 // currently requires a 'provisional' local frame to serve as a |
90 // placeholder for loading state when swapping to a local frame. | 90 // placeholder for loading state when swapping to a local frame. |
91 // In this case, the core LocalFrame is already initialized, so just | 91 // In this case, the core LocalFrame is already initialized, so just |
92 // update a bit of state. | 92 // update a bit of state. |
93 LocalFrame& local_frame = *ToWebLocalFrameImpl(frame)->GetFrame(); | 93 LocalFrame& local_frame = *ToWebLocalFrameImpl(frame)->GetFrame(); |
94 DCHECK_EQ(owner, local_frame.Owner()); | 94 DCHECK_EQ(owner, local_frame.Owner()); |
95 if (owner) { | 95 if (owner) { |
96 owner->SetContentFrame(local_frame); | 96 owner->SetContentFrame(local_frame); |
97 if (owner->IsLocal()) | 97 if (owner->IsLocal()) |
98 ToHTMLFrameOwnerElement(owner)->SetWidget(local_frame.View()); | 98 ToHTMLFrameOwnerElement(owner)->SetWidget(local_frame.View()); |
99 } else { | 99 } else { |
100 local_frame.GetPage()->SetMainFrame(&local_frame); | 100 local_frame.GetPage()->SetMainFrame(&local_frame); |
101 // This trace event is needed to detect the main frame of the | 101 // This trace event is needed to detect the main frame of the |
102 // renderer in telemetry metrics. See crbug.com/692112#c11. | 102 // renderer in telemetry metrics. See crbug.com/692112#c11. |
103 TRACE_EVENT_INSTANT1("loading", "markAsMainFrame", | 103 TRACE_EVENT_INSTANT1("loading", "markAsMainFrame", |
104 TRACE_EVENT_SCOPE_THREAD, "frame", &local_frame); | 104 TRACE_EVENT_SCOPE_THREAD, "frame", &local_frame); |
105 } | 105 } |
106 } else { | 106 } else { |
107 ToWebRemoteFrameImpl(frame)->InitializeCoreFrame(*page, owner, name); | 107 ToWebRemoteFrameImpl(frame)->InitializeCoreFrame(*page, owner, name); |
108 } | 108 } |
109 | 109 |
110 if (parent_ && old_frame->HasReceivedUserGesture()) | 110 if (parent_ && old_frame->HasReceivedUserGesture()) |
111 frame->ToImplBase()->GetFrame()->SetDocumentHasReceivedUserGesture(); | 111 ToCoreFrame(*frame)->SetDocumentHasReceivedUserGesture(); |
112 | 112 |
113 frame->ToImplBase()->GetFrame()->GetWindowProxyManager()->SetGlobalProxies( | 113 ToCoreFrame(*frame)->GetWindowProxyManager()->SetGlobalProxies( |
114 global_proxies); | 114 global_proxies); |
115 | 115 |
116 parent_ = nullptr; | 116 parent_ = nullptr; |
117 | 117 |
118 return true; | 118 return true; |
119 } | 119 } |
120 | 120 |
121 void WebFrame::Detach() { | 121 void WebFrame::Detach() { |
122 ToImplBase()->GetFrame()->Detach(FrameDetachType::kRemove); | 122 ToCoreFrame(*this)->Detach(FrameDetachType::kRemove); |
123 } | 123 } |
124 | 124 |
125 WebSecurityOrigin WebFrame::GetSecurityOrigin() const { | 125 WebSecurityOrigin WebFrame::GetSecurityOrigin() const { |
126 return WebSecurityOrigin( | 126 return WebSecurityOrigin( |
127 ToImplBase()->GetFrame()->GetSecurityContext()->GetSecurityOrigin()); | 127 ToCoreFrame(*this)->GetSecurityContext()->GetSecurityOrigin()); |
128 } | 128 } |
129 | 129 |
130 void WebFrame::SetFrameOwnerPolicy( | 130 void WebFrame::SetFrameOwnerPolicy( |
131 WebSandboxFlags flags, | 131 WebSandboxFlags flags, |
132 const blink::WebParsedFeaturePolicy& container_policy) { | 132 const blink::WebParsedFeaturePolicy& container_policy) { |
133 // At the moment, this is only used to replicate sandbox flags and container | 133 // At the moment, this is only used to replicate sandbox flags and container |
134 // policy for frames with a remote owner. | 134 // policy for frames with a remote owner. |
135 RemoteFrameOwner* owner = | 135 RemoteFrameOwner* owner = ToRemoteFrameOwner(ToCoreFrame(*this)->Owner()); |
136 ToRemoteFrameOwner(ToImplBase()->GetFrame()->Owner()); | |
137 DCHECK(owner); | 136 DCHECK(owner); |
138 owner->SetSandboxFlags(static_cast<SandboxFlags>(flags)); | 137 owner->SetSandboxFlags(static_cast<SandboxFlags>(flags)); |
139 owner->SetContainerPolicy(container_policy); | 138 owner->SetContainerPolicy(container_policy); |
140 } | 139 } |
141 | 140 |
142 WebInsecureRequestPolicy WebFrame::GetInsecureRequestPolicy() const { | 141 WebInsecureRequestPolicy WebFrame::GetInsecureRequestPolicy() const { |
143 return ToImplBase() | 142 return ToCoreFrame(*this)->GetSecurityContext()->GetInsecureRequestPolicy(); |
144 ->GetFrame() | |
145 ->GetSecurityContext() | |
146 ->GetInsecureRequestPolicy(); | |
147 } | 143 } |
148 | 144 |
149 void WebFrame::SetFrameOwnerProperties( | 145 void WebFrame::SetFrameOwnerProperties( |
150 const WebFrameOwnerProperties& properties) { | 146 const WebFrameOwnerProperties& properties) { |
151 // At the moment, this is only used to replicate frame owner properties | 147 // At the moment, this is only used to replicate frame owner properties |
152 // for frames with a remote owner. | 148 // for frames with a remote owner. |
153 RemoteFrameOwner* owner = | 149 RemoteFrameOwner* owner = ToRemoteFrameOwner(ToCoreFrame(*this)->Owner()); |
154 ToRemoteFrameOwner(ToImplBase()->GetFrame()->Owner()); | |
155 DCHECK(owner); | 150 DCHECK(owner); |
156 | 151 |
157 Frame* frame = ToImplBase()->GetFrame(); | 152 Frame* frame = ToCoreFrame(*this); |
158 DCHECK(frame); | 153 DCHECK(frame); |
159 | 154 |
160 if (frame->IsLocalFrame()) { | 155 if (frame->IsLocalFrame()) { |
161 ToLocalFrame(frame)->GetDocument()->WillChangeFrameOwnerProperties( | 156 ToLocalFrame(frame)->GetDocument()->WillChangeFrameOwnerProperties( |
162 properties.margin_width, properties.margin_height, | 157 properties.margin_width, properties.margin_height, |
163 static_cast<ScrollbarMode>(properties.scrolling_mode), | 158 static_cast<ScrollbarMode>(properties.scrolling_mode), |
164 properties.is_display_none); | 159 properties.is_display_none); |
165 } | 160 } |
166 | 161 |
167 owner->SetBrowsingContextContainerName(properties.name); | 162 owner->SetBrowsingContextContainerName(properties.name); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 new_child->previous_sibling_ = previous_sibling; | 197 new_child->previous_sibling_ = previous_sibling; |
203 } | 198 } |
204 | 199 |
205 if (next) { | 200 if (next) { |
206 new_child->next_sibling_ = next; | 201 new_child->next_sibling_ = next; |
207 next->previous_sibling_ = new_child; | 202 next->previous_sibling_ = new_child; |
208 } else { | 203 } else { |
209 last_child_ = new_child; | 204 last_child_ = new_child; |
210 } | 205 } |
211 | 206 |
212 ToImplBase()->GetFrame()->Tree().InvalidateScopedChildCount(); | 207 ToCoreFrame(*this)->Tree().InvalidateScopedChildCount(); |
213 ToImplBase()->GetFrame()->GetPage()->IncrementSubframeCount(); | 208 ToCoreFrame(*this)->GetPage()->IncrementSubframeCount(); |
214 } | 209 } |
215 | 210 |
216 void WebFrame::AppendChild(WebFrame* child) { | 211 void WebFrame::AppendChild(WebFrame* child) { |
217 // TODO(dcheng): Original code asserts that the frames have the same Page. | 212 // TODO(dcheng): Original code asserts that the frames have the same Page. |
218 // We should add an equivalent check... figure out what. | 213 // We should add an equivalent check... figure out what. |
219 InsertAfter(child, last_child_); | 214 InsertAfter(child, last_child_); |
220 } | 215 } |
221 | 216 |
222 void WebFrame::RemoveChild(WebFrame* child) { | 217 void WebFrame::RemoveChild(WebFrame* child) { |
223 child->parent_ = 0; | 218 child->parent_ = 0; |
224 | 219 |
225 if (first_child_ == child) | 220 if (first_child_ == child) |
226 first_child_ = child->next_sibling_; | 221 first_child_ = child->next_sibling_; |
227 else | 222 else |
228 child->previous_sibling_->next_sibling_ = child->next_sibling_; | 223 child->previous_sibling_->next_sibling_ = child->next_sibling_; |
229 | 224 |
230 if (last_child_ == child) | 225 if (last_child_ == child) |
231 last_child_ = child->previous_sibling_; | 226 last_child_ = child->previous_sibling_; |
232 else | 227 else |
233 child->next_sibling_->previous_sibling_ = child->previous_sibling_; | 228 child->next_sibling_->previous_sibling_ = child->previous_sibling_; |
234 | 229 |
235 child->previous_sibling_ = child->next_sibling_ = 0; | 230 child->previous_sibling_ = child->next_sibling_ = 0; |
236 | 231 |
237 ToImplBase()->GetFrame()->Tree().InvalidateScopedChildCount(); | 232 ToCoreFrame(*this)->Tree().InvalidateScopedChildCount(); |
238 ToImplBase()->GetFrame()->GetPage()->DecrementSubframeCount(); | 233 ToCoreFrame(*this)->GetPage()->DecrementSubframeCount(); |
239 } | 234 } |
240 | 235 |
241 void WebFrame::SetParent(WebFrame* parent) { | 236 void WebFrame::SetParent(WebFrame* parent) { |
242 parent_ = parent; | 237 parent_ = parent; |
243 } | 238 } |
244 | 239 |
245 WebFrame* WebFrame::Parent() const { | 240 WebFrame* WebFrame::Parent() const { |
246 return parent_; | 241 return parent_; |
247 } | 242 } |
248 | 243 |
249 WebFrame* WebFrame::Top() const { | 244 WebFrame* WebFrame::Top() const { |
250 WebFrame* frame = const_cast<WebFrame*>(this); | 245 WebFrame* frame = const_cast<WebFrame*>(this); |
251 for (WebFrame* parent = frame; parent; parent = parent->parent_) | 246 for (WebFrame* parent = frame; parent; parent = parent->parent_) |
252 frame = parent; | 247 frame = parent; |
253 return frame; | 248 return frame; |
254 } | 249 } |
255 | 250 |
256 WebFrame* WebFrame::FirstChild() const { | 251 WebFrame* WebFrame::FirstChild() const { |
257 return first_child_; | 252 return first_child_; |
258 } | 253 } |
259 | 254 |
260 WebFrame* WebFrame::NextSibling() const { | 255 WebFrame* WebFrame::NextSibling() const { |
261 return next_sibling_; | 256 return next_sibling_; |
262 } | 257 } |
263 | 258 |
264 WebFrame* WebFrame::TraverseNext() const { | 259 WebFrame* WebFrame::TraverseNext() const { |
265 if (Frame* frame = ToImplBase()->GetFrame()) | 260 if (Frame* frame = ToCoreFrame(*this)) |
266 return FromFrame(frame->Tree().TraverseNext()); | 261 return FromFrame(frame->Tree().TraverseNext()); |
267 return nullptr; | 262 return nullptr; |
268 } | 263 } |
269 | 264 |
270 WebFrame* WebFrame::FromFrameOwnerElement(const WebElement& web_element) { | 265 WebFrame* WebFrame::FromFrameOwnerElement(const WebElement& web_element) { |
271 Element* element = web_element; | 266 Element* element = web_element; |
272 | 267 |
273 if (!element->IsFrameOwnerElement()) | 268 if (!element->IsFrameOwnerElement()) |
274 return nullptr; | 269 return nullptr; |
275 return FromFrame(ToHTMLFrameOwnerElement(element)->ContentFrame()); | 270 return FromFrame(ToHTMLFrameOwnerElement(element)->ContentFrame()); |
276 } | 271 } |
277 | 272 |
278 bool WebFrame::IsLoading() const { | 273 bool WebFrame::IsLoading() const { |
279 if (Frame* frame = ToImplBase()->GetFrame()) | 274 if (Frame* frame = ToCoreFrame(*this)) |
280 return frame->IsLoading(); | 275 return frame->IsLoading(); |
281 return false; | 276 return false; |
282 } | 277 } |
283 | 278 |
284 WebFrame* WebFrame::FromFrame(Frame* frame) { | 279 WebFrame* WebFrame::FromFrame(Frame* frame) { |
285 if (!frame) | 280 if (!frame) |
286 return 0; | 281 return 0; |
287 | 282 |
288 if (frame->IsLocalFrame()) | 283 if (frame->IsLocalFrame()) |
289 return WebLocalFrameImpl::FromFrame(ToLocalFrame(*frame)); | 284 return WebLocalFrameImpl::FromFrame(ToLocalFrame(*frame)); |
(...skipping 29 matching lines...) Expand all Loading... |
319 TraceFrame(visitor, frame->parent_); | 314 TraceFrame(visitor, frame->parent_); |
320 for (WebFrame* child = frame->FirstChild(); child; | 315 for (WebFrame* child = frame->FirstChild(); child; |
321 child = child->NextSibling()) | 316 child = child->NextSibling()) |
322 TraceFrame(visitor, child); | 317 TraceFrame(visitor, child); |
323 } | 318 } |
324 | 319 |
325 void WebFrame::Close() { | 320 void WebFrame::Close() { |
326 opened_frame_tracker_->Dispose(); | 321 opened_frame_tracker_->Dispose(); |
327 } | 322 } |
328 | 323 |
| 324 void WebFrame::InitializeCoreFrame(WebFrame& frame, Page& page) { |
| 325 if (frame.IsWebLocalFrame()) |
| 326 ToWebLocalFrameImpl(frame).InitializeCoreFrame(page, 0, g_null_atom); |
| 327 else if (frame.IsWebRemoteFrame()) |
| 328 ToWebRemoteFrameImpl(frame).InitializeCoreFrame(page, 0, g_null_atom); |
| 329 else |
| 330 NOTREACHED(); |
| 331 } |
| 332 |
| 333 Frame* WebFrame::ToCoreFrame(const WebFrame& frame) { |
| 334 if (frame.IsWebLocalFrame()) |
| 335 return ToWebLocalFrameImpl(frame).GetFrame(); |
| 336 if (frame.IsWebRemoteFrame()) |
| 337 return ToWebRemoteFrameImpl(frame).GetFrame(); |
| 338 NOTREACHED(); |
| 339 return nullptr; |
| 340 } |
| 341 |
329 } // namespace blink | 342 } // namespace blink |
OLD | NEW |