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

Side by Side Diff: third_party/WebKit/Source/web/WebFrame.cpp

Issue 2837593002: Nuked WebFrameImplBase. (Closed)
Patch Set: Switched to static methods. Created 3 years, 7 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 // 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
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 = CoreFrame(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
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 CoreFrame(frame)->SetDocumentHasReceivedUserGesture();
112 112
113 frame->ToImplBase()->GetFrame()->GetWindowProxyManager()->SetGlobalProxies( 113 CoreFrame(frame)->GetWindowProxyManager()->SetGlobalProxies(global_proxies);
114 global_proxies);
115 114
116 parent_ = nullptr; 115 parent_ = nullptr;
117 116
118 return true; 117 return true;
119 } 118 }
120 119
121 void WebFrame::Detach() { 120 void WebFrame::Detach() {
122 ToImplBase()->GetFrame()->Detach(FrameDetachType::kRemove); 121 CoreFrame(this)->Detach(FrameDetachType::kRemove);
123 } 122 }
124 123
125 WebSecurityOrigin WebFrame::GetSecurityOrigin() const { 124 WebSecurityOrigin WebFrame::GetSecurityOrigin() const {
126 return WebSecurityOrigin( 125 return WebSecurityOrigin(
127 ToImplBase()->GetFrame()->GetSecurityContext()->GetSecurityOrigin()); 126 CoreFrame(this)->GetSecurityContext()->GetSecurityOrigin());
128 } 127 }
129 128
130 void WebFrame::SetFrameOwnerPolicy( 129 void WebFrame::SetFrameOwnerPolicy(
131 WebSandboxFlags flags, 130 WebSandboxFlags flags,
132 const blink::WebParsedFeaturePolicy& container_policy) { 131 const blink::WebParsedFeaturePolicy& container_policy) {
133 // At the moment, this is only used to replicate sandbox flags and container 132 // At the moment, this is only used to replicate sandbox flags and container
134 // policy for frames with a remote owner. 133 // policy for frames with a remote owner.
135 RemoteFrameOwner* owner = 134 RemoteFrameOwner* owner = ToRemoteFrameOwner(CoreFrame(this)->Owner());
136 ToRemoteFrameOwner(ToImplBase()->GetFrame()->Owner());
137 DCHECK(owner); 135 DCHECK(owner);
138 owner->SetSandboxFlags(static_cast<SandboxFlags>(flags)); 136 owner->SetSandboxFlags(static_cast<SandboxFlags>(flags));
139 owner->SetContainerPolicy(container_policy); 137 owner->SetContainerPolicy(container_policy);
140 } 138 }
141 139
142 WebInsecureRequestPolicy WebFrame::GetInsecureRequestPolicy() const { 140 WebInsecureRequestPolicy WebFrame::GetInsecureRequestPolicy() const {
143 return ToImplBase() 141 return CoreFrame(this)->GetSecurityContext()->GetInsecureRequestPolicy();
144 ->GetFrame()
145 ->GetSecurityContext()
146 ->GetInsecureRequestPolicy();
147 } 142 }
148 143
149 void WebFrame::SetFrameOwnerProperties( 144 void WebFrame::SetFrameOwnerProperties(
150 const WebFrameOwnerProperties& properties) { 145 const WebFrameOwnerProperties& properties) {
151 // At the moment, this is only used to replicate frame owner properties 146 // At the moment, this is only used to replicate frame owner properties
152 // for frames with a remote owner. 147 // for frames with a remote owner.
153 RemoteFrameOwner* owner = 148 RemoteFrameOwner* owner = ToRemoteFrameOwner(CoreFrame(this)->Owner());
154 ToRemoteFrameOwner(ToImplBase()->GetFrame()->Owner());
155 DCHECK(owner); 149 DCHECK(owner);
156 150
157 Frame* frame = ToImplBase()->GetFrame(); 151 Frame* frame = CoreFrame(this);
158 DCHECK(frame); 152 DCHECK(frame);
159 153
160 if (frame->IsLocalFrame()) { 154 if (frame->IsLocalFrame()) {
161 ToLocalFrame(frame)->GetDocument()->WillChangeFrameOwnerProperties( 155 ToLocalFrame(frame)->GetDocument()->WillChangeFrameOwnerProperties(
162 properties.margin_width, properties.margin_height, 156 properties.margin_width, properties.margin_height,
163 static_cast<ScrollbarMode>(properties.scrolling_mode), 157 static_cast<ScrollbarMode>(properties.scrolling_mode),
164 properties.is_display_none); 158 properties.is_display_none);
165 } 159 }
166 160
167 owner->SetBrowsingContextContainerName(properties.name); 161 owner->SetBrowsingContextContainerName(properties.name);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 new_child->previous_sibling_ = previous_sibling; 196 new_child->previous_sibling_ = previous_sibling;
203 } 197 }
204 198
205 if (next) { 199 if (next) {
206 new_child->next_sibling_ = next; 200 new_child->next_sibling_ = next;
207 next->previous_sibling_ = new_child; 201 next->previous_sibling_ = new_child;
208 } else { 202 } else {
209 last_child_ = new_child; 203 last_child_ = new_child;
210 } 204 }
211 205
212 ToImplBase()->GetFrame()->Tree().InvalidateScopedChildCount(); 206 CoreFrame(this)->Tree().InvalidateScopedChildCount();
213 ToImplBase()->GetFrame()->GetPage()->IncrementSubframeCount(); 207 CoreFrame(this)->GetPage()->IncrementSubframeCount();
214 } 208 }
215 209
216 void WebFrame::AppendChild(WebFrame* child) { 210 void WebFrame::AppendChild(WebFrame* child) {
217 // TODO(dcheng): Original code asserts that the frames have the same Page. 211 // TODO(dcheng): Original code asserts that the frames have the same Page.
218 // We should add an equivalent check... figure out what. 212 // We should add an equivalent check... figure out what.
219 InsertAfter(child, last_child_); 213 InsertAfter(child, last_child_);
220 } 214 }
221 215
222 void WebFrame::RemoveChild(WebFrame* child) { 216 void WebFrame::RemoveChild(WebFrame* child) {
223 child->parent_ = 0; 217 child->parent_ = 0;
224 218
225 if (first_child_ == child) 219 if (first_child_ == child)
226 first_child_ = child->next_sibling_; 220 first_child_ = child->next_sibling_;
227 else 221 else
228 child->previous_sibling_->next_sibling_ = child->next_sibling_; 222 child->previous_sibling_->next_sibling_ = child->next_sibling_;
229 223
230 if (last_child_ == child) 224 if (last_child_ == child)
231 last_child_ = child->previous_sibling_; 225 last_child_ = child->previous_sibling_;
232 else 226 else
233 child->next_sibling_->previous_sibling_ = child->previous_sibling_; 227 child->next_sibling_->previous_sibling_ = child->previous_sibling_;
234 228
235 child->previous_sibling_ = child->next_sibling_ = 0; 229 child->previous_sibling_ = child->next_sibling_ = 0;
236 230
237 ToImplBase()->GetFrame()->Tree().InvalidateScopedChildCount(); 231 CoreFrame(this)->Tree().InvalidateScopedChildCount();
238 ToImplBase()->GetFrame()->GetPage()->DecrementSubframeCount(); 232 CoreFrame(this)->GetPage()->DecrementSubframeCount();
239 } 233 }
240 234
241 void WebFrame::SetParent(WebFrame* parent) { 235 void WebFrame::SetParent(WebFrame* parent) {
242 parent_ = parent; 236 parent_ = parent;
243 } 237 }
244 238
245 WebFrame* WebFrame::Parent() const { 239 WebFrame* WebFrame::Parent() const {
246 return parent_; 240 return parent_;
247 } 241 }
248 242
249 WebFrame* WebFrame::Top() const { 243 WebFrame* WebFrame::Top() const {
250 WebFrame* frame = const_cast<WebFrame*>(this); 244 WebFrame* frame = const_cast<WebFrame*>(this);
251 for (WebFrame* parent = frame; parent; parent = parent->parent_) 245 for (WebFrame* parent = frame; parent; parent = parent->parent_)
252 frame = parent; 246 frame = parent;
253 return frame; 247 return frame;
254 } 248 }
255 249
256 WebFrame* WebFrame::FirstChild() const { 250 WebFrame* WebFrame::FirstChild() const {
257 return first_child_; 251 return first_child_;
258 } 252 }
259 253
260 WebFrame* WebFrame::NextSibling() const { 254 WebFrame* WebFrame::NextSibling() const {
261 return next_sibling_; 255 return next_sibling_;
262 } 256 }
263 257
264 WebFrame* WebFrame::TraverseNext() const { 258 WebFrame* WebFrame::TraverseNext() const {
265 if (Frame* frame = ToImplBase()->GetFrame()) 259 if (Frame* frame = CoreFrame(this))
266 return FromFrame(frame->Tree().TraverseNext()); 260 return FromFrame(frame->Tree().TraverseNext());
267 return nullptr; 261 return nullptr;
268 } 262 }
269 263
270 WebFrame* WebFrame::FromFrameOwnerElement(const WebElement& web_element) { 264 WebFrame* WebFrame::FromFrameOwnerElement(const WebElement& web_element) {
271 Element* element = web_element; 265 Element* element = web_element;
272 266
273 if (!element->IsFrameOwnerElement()) 267 if (!element->IsFrameOwnerElement())
274 return nullptr; 268 return nullptr;
275 return FromFrame(ToHTMLFrameOwnerElement(element)->ContentFrame()); 269 return FromFrame(ToHTMLFrameOwnerElement(element)->ContentFrame());
276 } 270 }
277 271
278 bool WebFrame::IsLoading() const { 272 bool WebFrame::IsLoading() const {
279 if (Frame* frame = ToImplBase()->GetFrame()) 273 if (Frame* frame = CoreFrame(this))
280 return frame->IsLoading(); 274 return frame->IsLoading();
281 return false; 275 return false;
282 } 276 }
283 277
284 WebFrame* WebFrame::FromFrame(Frame* frame) { 278 WebFrame* WebFrame::FromFrame(Frame* frame) {
285 if (!frame) 279 if (!frame)
286 return 0; 280 return 0;
287 281
288 if (frame->IsLocalFrame()) 282 if (frame->IsLocalFrame())
289 return WebLocalFrameImpl::FromFrame(ToLocalFrame(*frame)); 283 return WebLocalFrameImpl::FromFrame(ToLocalFrame(*frame));
(...skipping 29 matching lines...) Expand all
319 TraceFrame(visitor, frame->parent_); 313 TraceFrame(visitor, frame->parent_);
320 for (WebFrame* child = frame->FirstChild(); child; 314 for (WebFrame* child = frame->FirstChild(); child;
321 child = child->NextSibling()) 315 child = child->NextSibling())
322 TraceFrame(visitor, child); 316 TraceFrame(visitor, child);
323 } 317 }
324 318
325 void WebFrame::Close() { 319 void WebFrame::Close() {
326 opened_frame_tracker_->Dispose(); 320 opened_frame_tracker_->Dispose();
327 } 321 }
328 322
323 void WebFrame::InitializeCoreFrame(WebFrame* frame, Page& page) {
324 if (frame->IsWebLocalFrame())
325 ToWebLocalFrameImpl(frame)->InitializeCoreFrame(page, 0, g_null_atom);
326 else if (frame->IsWebRemoteFrame())
327 ToWebRemoteFrameImpl(frame)->InitializeCoreFrame(page, 0, g_null_atom);
dcheng 2017/04/26 11:45:33 I think this is missing an else before the NOTREAC
mustaq 2017/04/26 18:12:48 Yikes! Done.
328 NOTREACHED();
329 }
330
331 Frame* WebFrame::CoreFrame(const WebFrame* frame) {
332 if (frame->IsWebLocalFrame())
333 return ToWebLocalFrameImpl(frame)->GetFrame();
334 if (frame->IsWebRemoteFrame())
335 return ToWebRemoteFrameImpl(frame)->GetFrame();
336 NOTREACHED();
337 return nullptr;
338 }
339
329 } // namespace blink 340 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698