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/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "content/browser/frame_host/frame_tree.h" | 11 #include "content/browser/frame_host/frame_tree.h" |
12 #include "content/browser/frame_host/navigator.h" | 12 #include "content/browser/frame_host/navigator.h" |
13 #include "content/browser/frame_host/render_frame_host_impl.h" | 13 #include "content/browser/frame_host/render_frame_host_impl.h" |
14 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // This is a global map between frame_tree_node_ids and pointers to | 22 // This is a global map between frame_tree_node_ids and pointers to |
23 // FrameTreeNodes. | 23 // FrameTreeNodes. |
24 typedef base::hash_map<int64, FrameTreeNode*> FrameTreeNodeIDMap; | 24 typedef base::hash_map<int64, FrameTreeNode*> FrameTreeNodeIDMap; |
25 | 25 |
26 base::LazyInstance<FrameTreeNodeIDMap> g_frame_tree_node_id_map = | 26 base::LazyInstance<FrameTreeNodeIDMap> g_frame_tree_node_id_map = |
27 LAZY_INSTANCE_INITIALIZER; | 27 LAZY_INSTANCE_INITIALIZER; |
28 | 28 |
| 29 // These values indicate the loading progress status. The minimum progress |
| 30 // value matches what Blink's ProgressTracker has traditionally used for a |
| 31 // minimum progress value. |
| 32 static const double kLoadingProgressNotStarted = 0.0; |
| 33 static const double kLoadingProgressMinimum = 0.1; |
| 34 static const double kLoadingProgressDone = 1.0; |
| 35 |
29 } // namespace | 36 } // namespace |
30 | 37 |
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; | 38 int64 FrameTreeNode::next_frame_tree_node_id_ = 1; |
36 | 39 |
37 // static | 40 // static |
38 FrameTreeNode* FrameTreeNode::GloballyFindByID(int64 frame_tree_node_id) { | 41 FrameTreeNode* FrameTreeNode::GloballyFindByID(int64 frame_tree_node_id) { |
39 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 42 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
40 FrameTreeNodeIDMap* nodes = g_frame_tree_node_id_map.Pointer(); | 43 FrameTreeNodeIDMap* nodes = g_frame_tree_node_id_map.Pointer(); |
41 FrameTreeNodeIDMap::iterator it = nodes->find(frame_tree_node_id); | 44 FrameTreeNodeIDMap::iterator it = nodes->find(frame_tree_node_id); |
42 return it == nodes->end() ? nullptr : it->second; | 45 return it == nodes->end() ? nullptr : it->second; |
43 } | 46 } |
44 | 47 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 return current_frame_host->is_loading(); | 170 return current_frame_host->is_loading(); |
168 } | 171 } |
169 | 172 |
170 bool FrameTreeNode::CommitPendingSandboxFlags() { | 173 bool FrameTreeNode::CommitPendingSandboxFlags() { |
171 bool did_change_flags = | 174 bool did_change_flags = |
172 effective_sandbox_flags_ != replication_state_.sandbox_flags; | 175 effective_sandbox_flags_ != replication_state_.sandbox_flags; |
173 effective_sandbox_flags_ = replication_state_.sandbox_flags; | 176 effective_sandbox_flags_ = replication_state_.sandbox_flags; |
174 return did_change_flags; | 177 return did_change_flags; |
175 } | 178 } |
176 | 179 |
| 180 bool FrameTreeNode::HasStartedLoading() const { |
| 181 return loading_progress_ != kLoadingProgressNotStarted; |
| 182 } |
| 183 |
| 184 void FrameTreeNode::ResetLoadingProgress() { |
| 185 loading_progress_ = kLoadingProgressNotStarted; |
| 186 } |
| 187 |
| 188 void FrameTreeNode::DidStartLoading(bool to_different_document) { |
| 189 // Any main frame load to a new document should reset the load progress since |
| 190 // it will replace the current page and any frames. The WebContents will |
| 191 // be notified when UpdateLoadProgress is called. |
| 192 if (to_different_document && IsMainFrame()) |
| 193 frame_tree_->ResetLoadProgress(); |
| 194 |
| 195 // Notify the Navigator. |
| 196 if (!frame_tree_->IsLoading()) |
| 197 navigator()->DidStartLoading(this, to_different_document); |
| 198 |
| 199 // Notify the RenderFrameHostManager of the event. |
| 200 render_manager()->OnDidStartLoading(); |
| 201 |
| 202 // Set initial load progress and update overall progress. This will notify |
| 203 // the WebContents of the load progress change. |
| 204 loading_progress_ = kLoadingProgressMinimum; |
| 205 frame_tree_->UpdateLoadProgress(); |
| 206 } |
| 207 |
| 208 void FrameTreeNode::DidStopLoading() { |
| 209 // Notify the RenderFrameHostManager of the event. |
| 210 render_manager()->OnDidStopLoading(); |
| 211 |
| 212 // Set final load progress and update overall progress. This will notify |
| 213 // the WebContents of the load progress change. |
| 214 loading_progress_ = kLoadingProgressDone; |
| 215 frame_tree_->UpdateLoadProgress(); |
| 216 |
| 217 // Notify the Navigator. |
| 218 if (!frame_tree_->IsLoading()) |
| 219 navigator()->DidStopLoading(); |
| 220 } |
| 221 |
| 222 void FrameTreeNode::DidChangeLoadProgress(double load_progress) { |
| 223 loading_progress_ = load_progress; |
| 224 frame_tree_->UpdateLoadProgress(); |
| 225 } |
| 226 |
177 } // namespace content | 227 } // namespace content |
OLD | NEW |