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 { |
| 182 return loading_progress_ != kLoadingProgressNotStarted; |
| 183 } |
| 184 |
| 185 void FrameTreeNode::ResetLoadingProgress() { |
| 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 DidChangeLoadProgress 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 // Set initial load progress and update overall progress. This will notify |
| 201 // the WebContents of the load progress change. |
| 202 DidChangeLoadProgress(kLoadingProgressMinimum); |
| 203 |
| 204 // Notify the RenderFrameHostManager of the event. |
| 205 render_manager()->OnDidStartLoading(); |
| 206 } |
| 207 |
| 208 void FrameTreeNode::DidStopLoading() { |
| 209 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is fixed. |
| 210 tracked_objects::ScopedTracker tracking_profile1( |
| 211 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 212 "465796 FrameTreeNode::DidStopLoading::Start")); |
| 213 |
| 214 // Set final load progress and update overall progress. This will notify |
| 215 // the WebContents of the load progress change. |
| 216 DidChangeLoadProgress(kLoadingProgressDone); |
| 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::WCIDidStopLoading")); |
| 222 |
| 223 // Notify the WebContents. |
| 224 if (!frame_tree_->IsLoading()) |
| 225 navigator()->GetDelegate()->DidStopLoading(); |
| 226 |
| 227 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is fixed. |
| 228 tracked_objects::ScopedTracker tracking_profile3( |
| 229 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 230 "465796 FrameTreeNode::DidStopLoading::RFHMDidStopLoading")); |
| 231 |
| 232 // Notify the RenderFrameHostManager of the event. |
| 233 render_manager()->OnDidStopLoading(); |
| 234 |
| 235 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is fixed. |
| 236 tracked_objects::ScopedTracker tracking_profile4( |
| 237 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 238 "465796 FrameTreeNode::DidStopLoading::End")); |
| 239 } |
| 240 |
| 241 void FrameTreeNode::DidChangeLoadProgress(double load_progress) { |
| 242 loading_progress_ = load_progress; |
| 243 frame_tree_->UpdateLoadProgress(); |
| 244 } |
| 245 |
177 } // namespace content | 246 } // namespace content |
OLD | NEW |