Chromium Code Reviews| 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 /* | 5 /* |
| 6 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 6 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
| 9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
| 10 * | 10 * |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 28 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 */ | 34 */ |
| 35 | 35 |
| 36 #include "content/renderer/history_controller.h" | 36 #include "content/renderer/history_controller.h" |
| 37 | 37 |
| 38 #include <deque> | |
| 39 | |
| 40 #include "content/renderer/render_frame_impl.h" | 38 #include "content/renderer/render_frame_impl.h" |
| 41 #include "content/renderer/render_view_impl.h" | 39 #include "content/renderer/render_view_impl.h" |
| 42 #include "third_party/WebKit/public/platform/WebVector.h" | |
| 43 #include "third_party/WebKit/public/web/WebFrame.h" | 40 #include "third_party/WebKit/public/web/WebFrame.h" |
| 44 | 41 |
| 45 using blink::WebFrame; | 42 using blink::WebFrame; |
| 46 using blink::WebHistoryCommitType; | 43 using blink::WebHistoryCommitType; |
| 47 using blink::WebHistoryItem; | 44 using blink::WebHistoryItem; |
| 48 using blink::WebURLRequest; | 45 using blink::WebURLRequest; |
| 49 using blink::WebVector; | |
| 50 | 46 |
| 51 namespace content { | 47 namespace content { |
| 52 | 48 |
| 53 HistoryController::HistoryController(RenderViewImpl* render_view) | 49 HistoryController::HistoryController(RenderViewImpl* render_view) |
| 54 : render_view_(render_view) { | 50 : render_view_(render_view) { |
| 55 } | 51 } |
| 56 | 52 |
| 57 HistoryController::~HistoryController() { | 53 HistoryController::~HistoryController() { |
| 58 } | 54 } |
| 59 | 55 |
| 60 void HistoryController::GoToEntry(HistoryEntry* target_entry, | 56 void HistoryController::GoToEntry(HistoryEntry* target_entry, |
| 61 WebURLRequest::CachePolicy cache_policy) { | 57 WebURLRequest::CachePolicy cache_policy) { |
| 62 HistoryFrameLoadVector same_document_loads; | 58 HistoryFrameLoadVector same_document_loads; |
| 63 HistoryFrameLoadVector different_document_loads; | 59 HistoryFrameLoadVector different_document_loads; |
| 64 | 60 |
| 65 provisional_entry_.reset(target_entry); | 61 provisional_entry_.reset(target_entry); |
| 66 | 62 |
| 67 WebFrame* main_frame = render_view_->main_render_frame()->GetWebFrame(); | 63 WebFrame* main_frame = render_view_->main_render_frame()->GetWebFrame(); |
| 68 if (current_entry_) { | 64 if (current_entry_) { |
| 69 RecursiveGoToEntry( | 65 RecursiveGoToEntry( |
| 70 main_frame, same_document_loads, different_document_loads); | 66 main_frame, same_document_loads, different_document_loads); |
| 71 } else { | |
| 72 different_document_loads.push_back( | |
| 73 std::make_pair(main_frame, provisional_entry_->root())); | |
| 74 } | 67 } |
| 75 | 68 |
| 76 if (same_document_loads.empty() && different_document_loads.empty()) { | 69 if (same_document_loads.empty() && different_document_loads.empty()) { |
| 77 same_document_loads.push_back( | 70 different_document_loads.push_back( |
|
Nate Chapin
2014/04/28 23:08:47
I can't find a compelling reason I used same_docum
Charlie Reis
2014/04/29 00:24:37
Hmm, I don't understand this at all. Can you expl
Nate Chapin
2014/04/29 19:31:53
Comments added to both modified if() blocks.
| |
| 78 std::make_pair(main_frame, provisional_entry_->root())); | 71 std::make_pair(main_frame, provisional_entry_->root())); |
| 79 } | 72 } else if (different_document_loads.empty()) { |
| 80 | |
| 81 if (different_document_loads.empty()) { | |
| 82 previous_entry_.reset(current_entry_.release()); | 73 previous_entry_.reset(current_entry_.release()); |
| 83 current_entry_.reset(provisional_entry_.release()); | 74 current_entry_.reset(provisional_entry_.release()); |
| 84 } | 75 } |
| 85 | 76 |
| 86 for (size_t i = 0; i < same_document_loads.size(); ++i) { | 77 for (size_t i = 0; i < same_document_loads.size(); ++i) { |
| 87 WebFrame* frame = same_document_loads[i].first; | 78 WebFrame* frame = same_document_loads[i].first; |
| 88 if (!RenderFrameImpl::FromWebFrame(frame)) | 79 if (!RenderFrameImpl::FromWebFrame(frame)) |
| 89 continue; | 80 continue; |
| 90 frame->loadHistoryItem(same_document_loads[i].second, | 81 frame->loadHistoryItem(same_document_loads[i].second, |
| 91 blink::WebHistorySameDocumentLoad, | 82 blink::WebHistorySameDocumentLoad, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 different_document_loads.push_back(std::make_pair(frame, new_item)); | 115 different_document_loads.push_back(std::make_pair(frame, new_item)); |
| 125 return; | 116 return; |
| 126 } | 117 } |
| 127 | 118 |
| 128 for (WebFrame* child = frame->firstChild(); child; | 119 for (WebFrame* child = frame->firstChild(); child; |
| 129 child = child->nextSibling()) { | 120 child = child->nextSibling()) { |
| 130 RecursiveGoToEntry(child, same_document_loads, different_document_loads); | 121 RecursiveGoToEntry(child, same_document_loads, different_document_loads); |
| 131 } | 122 } |
| 132 } | 123 } |
| 133 | 124 |
| 134 void HistoryController::GoToItem(const WebHistoryItem& target_item, | |
| 135 WebURLRequest::CachePolicy cache_policy) { | |
| 136 // We don't have enough information to set a correct frame id here. This | |
| 137 // might be a restore from disk, and the frame ids might not match up if the | |
| 138 // state was saved from a different process. Ensure the HistoryEntry's main | |
| 139 // frame id matches the actual main frame id. Its subframe ids are invalid to | |
| 140 // ensure they don't accidentally match a potentially random frame. | |
| 141 HistoryEntry* new_entry = new HistoryEntry( | |
| 142 target_item, render_view_->main_render_frame()->GetRoutingID()); | |
| 143 std::deque<HistoryEntry::HistoryNode*> history_nodes; | |
| 144 history_nodes.push_back(new_entry->root_history_node()); | |
| 145 while (!history_nodes.empty()) { | |
| 146 // For each item, read the children (if any) off the WebHistoryItem, | |
| 147 // create a new HistoryNode for each child and attach it, | |
| 148 // then clear the children on the WebHistoryItem. | |
| 149 HistoryEntry::HistoryNode* history_node = history_nodes.front(); | |
| 150 history_nodes.pop_front(); | |
| 151 | |
| 152 WebVector<WebHistoryItem> children = history_node->item().children(); | |
| 153 for (size_t i = 0; i < children.size(); i++) { | |
| 154 HistoryEntry::HistoryNode* child_history_node = | |
| 155 history_node->AddChild(children[i], kInvalidFrameRoutingID); | |
| 156 history_nodes.push_back(child_history_node); | |
| 157 } | |
| 158 history_node->item().setChildren(WebVector<WebHistoryItem>()); | |
| 159 } | |
| 160 GoToEntry(new_entry, cache_policy); | |
| 161 } | |
| 162 | |
| 163 void HistoryController::UpdateForInitialLoadInChildFrame( | 125 void HistoryController::UpdateForInitialLoadInChildFrame( |
| 164 RenderFrameImpl* frame, | 126 RenderFrameImpl* frame, |
| 165 const WebHistoryItem& item) { | 127 const WebHistoryItem& item) { |
| 166 DCHECK_NE(frame->GetWebFrame()->top(), frame->GetWebFrame()); | 128 DCHECK_NE(frame->GetWebFrame()->top(), frame->GetWebFrame()); |
| 167 if (!current_entry_) | 129 if (!current_entry_) |
| 168 return; | 130 return; |
| 169 if (HistoryEntry::HistoryNode* existing_node = | 131 if (HistoryEntry::HistoryNode* existing_node = |
| 170 current_entry_->GetHistoryNodeForFrame(frame)) { | 132 current_entry_->GetHistoryNodeForFrame(frame)) { |
| 171 existing_node->set_item(item); | 133 existing_node->set_item(item); |
| 172 return; | 134 return; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 188 return; | 150 return; |
| 189 previous_entry_.reset(current_entry_.release()); | 151 previous_entry_.reset(current_entry_.release()); |
| 190 current_entry_.reset(provisional_entry_.release()); | 152 current_entry_.reset(provisional_entry_.release()); |
| 191 } else if (commit_type == blink::WebStandardCommit) { | 153 } else if (commit_type == blink::WebStandardCommit) { |
| 192 CreateNewBackForwardItem(frame, item, navigation_within_page); | 154 CreateNewBackForwardItem(frame, item, navigation_within_page); |
| 193 } else if (commit_type == blink::WebInitialCommitInChildFrame) { | 155 } else if (commit_type == blink::WebInitialCommitInChildFrame) { |
| 194 UpdateForInitialLoadInChildFrame(frame, item); | 156 UpdateForInitialLoadInChildFrame(frame, item); |
| 195 } | 157 } |
| 196 } | 158 } |
| 197 | 159 |
| 198 static WebHistoryItem ItemForExport(HistoryEntry::HistoryNode* history_node) { | 160 HistoryEntry* HistoryController::GetCurrentEntry() { |
| 199 DCHECK(history_node); | 161 return current_entry_.get(); |
| 200 WebHistoryItem item = history_node->item(); | |
| 201 item.setChildren(WebVector<WebHistoryItem>()); | |
| 202 std::vector<HistoryEntry::HistoryNode*>& child_nodes = | |
| 203 history_node->children(); | |
| 204 for (size_t i = 0; i < child_nodes.size(); i++) | |
| 205 item.appendToChildren(ItemForExport(child_nodes.at(i))); | |
| 206 return item; | |
| 207 } | 162 } |
| 208 | 163 |
| 209 WebHistoryItem HistoryController::GetCurrentItemForExport() { | 164 HistoryEntry* HistoryController::GetPreviousEntry() { |
| 210 if (!current_entry_) | 165 return previous_entry_.get(); |
| 211 return WebHistoryItem(); | |
| 212 return ItemForExport(current_entry_->root_history_node()); | |
| 213 } | |
| 214 | |
| 215 WebHistoryItem HistoryController::GetPreviousItemForExport() { | |
| 216 if (!previous_entry_) | |
| 217 return WebHistoryItem(); | |
| 218 return ItemForExport(previous_entry_->root_history_node()); | |
| 219 } | 166 } |
| 220 | 167 |
| 221 WebHistoryItem HistoryController::GetItemForNewChildFrame( | 168 WebHistoryItem HistoryController::GetItemForNewChildFrame( |
| 222 RenderFrameImpl* frame) const { | 169 RenderFrameImpl* frame) const { |
| 223 if (!current_entry_) | 170 if (!current_entry_) |
| 224 return WebHistoryItem(); | 171 return WebHistoryItem(); |
| 225 return current_entry_->GetItemForFrame(frame); | 172 return current_entry_->GetItemForFrame(frame); |
| 226 } | 173 } |
| 227 | 174 |
| 228 void HistoryController::RemoveChildrenForRedirect(RenderFrameImpl* frame) { | 175 void HistoryController::RemoveChildrenForRedirect(RenderFrameImpl* frame) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 241 current_entry_.reset( | 188 current_entry_.reset( |
| 242 new HistoryEntry(new_item, target_frame->GetRoutingID())); | 189 new HistoryEntry(new_item, target_frame->GetRoutingID())); |
| 243 } else { | 190 } else { |
| 244 previous_entry_.reset(current_entry_.release()); | 191 previous_entry_.reset(current_entry_.release()); |
| 245 current_entry_.reset(previous_entry_->CloneAndReplace( | 192 current_entry_.reset(previous_entry_->CloneAndReplace( |
| 246 new_item, clone_children_of_target, target_frame, render_view_)); | 193 new_item, clone_children_of_target, target_frame, render_view_)); |
| 247 } | 194 } |
| 248 } | 195 } |
| 249 | 196 |
| 250 } // namespace content | 197 } // namespace content |
| OLD | NEW |