OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/frame_host/frame_tree_node.h" | 5 #include "content/browser/frame_host/frame_tree_node.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/profiler/scoped_tracker.h" | |
10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
11 #include "content/browser/frame_host/frame_tree.h" | 12 #include "content/browser/frame_host/frame_tree.h" |
12 #include "content/browser/frame_host/navigator.h" | 13 #include "content/browser/frame_host/navigator.h" |
13 #include "content/browser/frame_host/render_frame_host_impl.h" | 14 #include "content/browser/frame_host/render_frame_host_impl.h" |
14 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // This is a global map between frame_tree_node_ids and pointers to | 23 // This is a global map between frame_tree_node_ids and pointers to |
23 // FrameTreeNodes. | 24 // FrameTreeNodes. |
24 typedef base::hash_map<int64, FrameTreeNode*> FrameTreeNodeIDMap; | 25 typedef base::hash_map<int64, FrameTreeNode*> FrameTreeNodeIDMap; |
25 | 26 |
26 base::LazyInstance<FrameTreeNodeIDMap> g_frame_tree_node_id_map = | 27 base::LazyInstance<FrameTreeNodeIDMap> g_frame_tree_node_id_map = |
27 LAZY_INSTANCE_INITIALIZER; | 28 LAZY_INSTANCE_INITIALIZER; |
28 | 29 |
30 // These values indicate the loading progress status. The minimum progress | |
31 // value matches what Blink's ProgressTracker has traditionally used for a | |
32 // minimum progress value. | |
33 const double kLoadingProgressNotStarted = 0.0; | |
34 const double kLoadingProgressMinimum = 0.1; | |
35 const double kLoadingProgressDone = 1.0; | |
36 | |
29 } // namespace | 37 } // namespace |
30 | 38 |
31 const double FrameTreeNode::kLoadingProgressNotStarted = 0.0; | |
32 const double FrameTreeNode::kLoadingProgressMinimum = 0.1; | |
33 const double FrameTreeNode::kLoadingProgressDone = 1.0; | |
34 | |
35 int64 FrameTreeNode::next_frame_tree_node_id_ = 1; | 39 int64 FrameTreeNode::next_frame_tree_node_id_ = 1; |
36 | 40 |
37 // static | 41 // static |
38 FrameTreeNode* FrameTreeNode::GloballyFindByID(int64 frame_tree_node_id) { | 42 FrameTreeNode* FrameTreeNode::GloballyFindByID(int64 frame_tree_node_id) { |
39 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 43 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
40 FrameTreeNodeIDMap* nodes = g_frame_tree_node_id_map.Pointer(); | 44 FrameTreeNodeIDMap* nodes = g_frame_tree_node_id_map.Pointer(); |
41 FrameTreeNodeIDMap::iterator it = nodes->find(frame_tree_node_id); | 45 FrameTreeNodeIDMap::iterator it = nodes->find(frame_tree_node_id); |
42 return it == nodes->end() ? nullptr : it->second; | 46 return it == nodes->end() ? nullptr : it->second; |
43 } | 47 } |
44 | 48 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 return current_frame_host->is_loading(); | 171 return current_frame_host->is_loading(); |
168 } | 172 } |
169 | 173 |
170 bool FrameTreeNode::CommitPendingSandboxFlags() { | 174 bool FrameTreeNode::CommitPendingSandboxFlags() { |
171 bool did_change_flags = | 175 bool did_change_flags = |
172 effective_sandbox_flags_ != replication_state_.sandbox_flags; | 176 effective_sandbox_flags_ != replication_state_.sandbox_flags; |
173 effective_sandbox_flags_ = replication_state_.sandbox_flags; | 177 effective_sandbox_flags_ = replication_state_.sandbox_flags; |
174 return did_change_flags; | 178 return did_change_flags; |
175 } | 179 } |
176 | 180 |
181 bool FrameTreeNode::HasStartedLoading() const { | |
Charlie Reis
2015/04/15 23:37:53
This should be in the .h file as has_started_loadi
Fabrice (no longer in Chrome)
2015/04/16 13:55:25
Then we'd have to move the kLoadingProgress consta
nasko
2015/04/16 16:23:48
It still should be hacker_cased though, as it just
Fabrice (no longer in Chrome)
2015/04/16 16:33:30
Done.
| |
182 return loading_progress_ != kLoadingProgressNotStarted; | |
183 } | |
184 | |
185 void FrameTreeNode::ResetLoadingProgress() { | |
Charlie Reis
2015/04/15 23:37:53
Same: reset_loading_progress().
Fabrice (no longer in Chrome)
2015/04/16 13:55:25
Same as above.
nasko
2015/04/16 16:23:48
Again, hacker_cased.
Fabrice (no longer in Chrome)
2015/04/16 16:33:30
Done.
| |
186 loading_progress_ = kLoadingProgressNotStarted; | |
187 } | |
188 | |
189 void FrameTreeNode::DidStartLoading(bool to_different_document) { | |
190 // Any main frame load to a new document should reset the load progress since | |
191 // it will replace the current page and any frames. The WebContents will | |
192 // be notified when UpdateLoadProgress is called. | |
193 if (to_different_document && IsMainFrame()) | |
194 frame_tree_->ResetLoadProgress(); | |
195 | |
196 // Notify the WebContents. | |
197 if (!frame_tree_->IsLoading()) | |
198 navigator()->GetDelegate()->DidStartLoading(this, to_different_document); | |
199 | |
200 // Notify the RenderFrameHostManager of the event. | |
nasko
2015/04/15 19:17:05
I wonder if it will be more consistent if all noti
Fabrice (no longer in Chrome)
2015/04/16 13:55:25
I am not sure what you are referring to, afaict RF
nasko
2015/04/16 16:23:48
My concerns are addressed by the usage of DidChang
| |
201 render_manager()->OnDidStartLoading(); | |
202 | |
203 // Set initial load progress and update overall progress. This will notify | |
204 // the WebContents of the load progress change. | |
205 loading_progress_ = kLoadingProgressMinimum; | |
206 frame_tree_->UpdateLoadProgress(); | |
Charlie Reis
2015/04/15 23:37:53
We should probably use DidChangeLoadProgress here
Fabrice (no longer in Chrome)
2015/04/16 13:55:25
Done.
Also updated the comments.
| |
207 } | |
208 | |
209 void FrameTreeNode::DidStopLoading() { | |
210 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is fixed. | |
211 tracked_objects::ScopedTracker tracking_profile1( | |
212 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
213 "465796 FrameTreeNode::DidStopLoading::Start")); | |
214 | |
215 // Notify the RenderFrameHostManager of the event. | |
216 render_manager()->OnDidStopLoading(); | |
nasko
2015/04/15 19:17:05
Same concern as above, should we change the state
Fabrice (no longer in Chrome)
2015/04/16 13:55:25
Moved that at the end of the method.
| |
217 | |
218 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is fixed. | |
219 tracked_objects::ScopedTracker tracking_profile2( | |
220 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
221 "465796 FrameTreeNode::DidStopLoading::UpdateLoadProgress")); | |
222 | |
223 // Set final load progress and update overall progress. This will notify | |
224 // the WebContents of the load progress change. | |
225 loading_progress_ = kLoadingProgressDone; | |
226 frame_tree_->UpdateLoadProgress(); | |
Charlie Reis
2015/04/15 23:37:53
Same here: call DidChangeLoadProgress.
Fabrice (no longer in Chrome)
2015/04/16 13:55:25
Done.
| |
227 | |
228 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is fixed. | |
229 tracked_objects::ScopedTracker tracking_profile3( | |
230 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
231 "465796 FrameTreeNode::DidStopLoading::WCIDidStopLoading")); | |
232 | |
233 // Notify the WebContents. | |
234 if (!frame_tree_->IsLoading()) | |
235 navigator()->GetDelegate()->DidStopLoading(); | |
236 | |
237 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is fixed. | |
238 tracked_objects::ScopedTracker tracking_profile4( | |
239 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
240 "465796 FrameTreeNode::DidStopLoading::End")); | |
241 } | |
242 | |
243 void FrameTreeNode::DidChangeLoadProgress(double load_progress) { | |
244 loading_progress_ = load_progress; | |
245 frame_tree_->UpdateLoadProgress(); | |
246 } | |
247 | |
177 } // namespace content | 248 } // namespace content |
OLD | NEW |