Chromium Code Reviews| 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/navigation_entry_impl.h" | 5 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 6 | 6 |
| 7 #include <queue> | 7 #include <queue> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "components/url_formatter/url_formatter.h" | 12 #include "components/url_formatter/url_formatter.h" |
| 13 #include "content/common/navigation_params.h" | 13 #include "content/common/navigation_params.h" |
| 14 #include "content/common/page_state_serialization.h" | 14 #include "content/common/page_state_serialization.h" |
| 15 #include "content/common/site_isolation_policy.h" | 15 #include "content/common/site_isolation_policy.h" |
| 16 #include "content/public/common/content_constants.h" | 16 #include "content/public/common/content_constants.h" |
| 17 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
| 18 #include "ui/gfx/text_elider.h" | 18 #include "ui/gfx/text_elider.h" |
| 19 | 19 |
| 20 using base::UTF16ToUTF8; | |
| 21 | |
| 22 namespace content { | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 20 // Use this to get a new unique ID for a NavigationEntry during construction. | 26 // Use this to get a new unique ID for a NavigationEntry during construction. |
| 21 // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). | 27 // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). |
| 22 static int GetUniqueIDInConstructor() { | 28 static int GetUniqueIDInConstructor() { |
|
Avi (use Gerrit)
2015/12/02 19:17:43
Now that this is in an anonymous namespace, you ca
Charlie Reis
2015/12/02 20:44:14
Done.
| |
| 23 static int unique_id_counter = 0; | 29 static int unique_id_counter = 0; |
| 24 return ++unique_id_counter; | 30 return ++unique_id_counter; |
| 25 } | 31 } |
| 26 | 32 |
| 27 namespace content { | 33 void RecursivelyGenerateFrameEntries(const ExplodedFrameState& state, |
| 34 NavigationEntryImpl::TreeNode* node) { | |
| 35 node->frame_entry = new FrameNavigationEntry( | |
| 36 -1, UTF16ToUTF8(state.target.string()), state.item_sequence_number, | |
| 37 state.document_sequence_number, nullptr, GURL(state.url_string.string()), | |
| 38 Referrer(GURL(state.referrer.string()), state.referrer_policy)); | |
| 39 | |
| 40 // Set a single-frame PageState on the entry. | |
| 41 ExplodedPageState page_state; | |
| 42 page_state.top = state; | |
| 43 std::string data; | |
| 44 if (EncodePageState(page_state, &data)) | |
| 45 node->frame_entry->set_page_state(PageState::CreateFromEncodedData(data)); | |
| 46 | |
| 47 for (const ExplodedFrameState& child_state : state.children) { | |
| 48 NavigationEntryImpl::TreeNode* child_node = | |
| 49 new NavigationEntryImpl::TreeNode(nullptr); | |
| 50 node->children.push_back(child_node); | |
| 51 RecursivelyGenerateFrameEntries(child_state, child_node); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 void RecursivelyGenerateFrameState( | |
| 56 NavigationEntryImpl::TreeNode* node, | |
| 57 ExplodedFrameState* state, | |
| 58 std::vector<base::NullableString16>* referenced_files) { | |
| 59 // The FrameNavigationEntry's PageState contains just the ExplodedFrameState | |
| 60 // for that particular frame. | |
| 61 ExplodedPageState exploded_page_state; | |
| 62 if (!DecodePageState(node->frame_entry->page_state().ToEncodedData(), | |
| 63 &exploded_page_state)) { | |
| 64 NOTREACHED(); | |
| 65 return; | |
| 66 } | |
| 67 ExplodedFrameState frame_state = exploded_page_state.top; | |
| 68 | |
| 69 // Copy the FrameNavigationEntry's frame state into the destination state. | |
| 70 *state = frame_state; | |
| 71 | |
| 72 // Copy the frame's files into the PageState's |referenced_files|. | |
| 73 referenced_files->reserve( | |
| 74 referenced_files->size() + exploded_page_state.referenced_files.size()); | |
| 75 for (auto& file : exploded_page_state.referenced_files) | |
| 76 referenced_files->push_back(file); | |
| 77 | |
| 78 state->children.resize(node->children.size()); | |
| 79 for (size_t i = 0; i < node->children.size(); ++i) { | |
| 80 RecursivelyGenerateFrameState(node->children[i], &state->children[i], | |
| 81 referenced_files); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 } // namespace | |
| 28 | 86 |
| 29 int NavigationEntryImpl::kInvalidBindings = -1; | 87 int NavigationEntryImpl::kInvalidBindings = -1; |
| 30 | 88 |
| 31 NavigationEntryImpl::TreeNode::TreeNode(FrameNavigationEntry* frame_entry) | 89 NavigationEntryImpl::TreeNode::TreeNode(FrameNavigationEntry* frame_entry) |
| 32 : frame_entry(frame_entry) { | 90 : frame_entry(frame_entry) { |
| 33 } | 91 } |
| 34 | 92 |
| 35 NavigationEntryImpl::TreeNode::~TreeNode() { | 93 NavigationEntryImpl::TreeNode::~TreeNode() { |
| 36 } | 94 } |
| 37 | 95 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 void NavigationEntryImpl::SetTitle(const base::string16& title) { | 231 void NavigationEntryImpl::SetTitle(const base::string16& title) { |
| 174 title_ = title; | 232 title_ = title; |
| 175 cached_display_title_.clear(); | 233 cached_display_title_.clear(); |
| 176 } | 234 } |
| 177 | 235 |
| 178 const base::string16& NavigationEntryImpl::GetTitle() const { | 236 const base::string16& NavigationEntryImpl::GetTitle() const { |
| 179 return title_; | 237 return title_; |
| 180 } | 238 } |
| 181 | 239 |
| 182 void NavigationEntryImpl::SetPageState(const PageState& state) { | 240 void NavigationEntryImpl::SetPageState(const PageState& state) { |
| 183 frame_tree_->frame_entry->set_page_state(state); | 241 page_state_ = state; |
| 184 | 242 |
| 185 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { | 243 if (!SiteIsolationPolicy::UseSubframeNavigationEntries()) |
| 186 // Also get the root ISN and DSN out of the PageState. | 244 return; |
| 187 ExplodedPageState exploded_state; | 245 |
| 188 if (!DecodePageState(state.ToEncodedData(), &exploded_state)) | 246 // This should only be called when restoring a NavigationEntry, so there |
| 189 return; | 247 // should be no subframe FrameNavigationEntries yet. |
| 190 frame_tree_->frame_entry->set_item_sequence_number( | 248 DCHECK_EQ(0U, frame_tree_->children.size()); |
| 191 exploded_state.top.item_sequence_number); | 249 |
| 192 frame_tree_->frame_entry->set_document_sequence_number( | 250 ExplodedPageState exploded_state; |
| 193 exploded_state.top.document_sequence_number); | 251 if (!DecodePageState(state.ToEncodedData(), &exploded_state)) |
| 194 } | 252 return; |
| 253 | |
| 254 RecursivelyGenerateFrameEntries(exploded_state.top, frame_tree_.get()); | |
| 195 } | 255 } |
| 196 | 256 |
| 197 const PageState& NavigationEntryImpl::GetPageState() const { | 257 const PageState& NavigationEntryImpl::GetPageState() const { |
| 198 return frame_tree_->frame_entry->page_state(); | 258 return page_state_; |
| 259 } | |
| 260 | |
| 261 void NavigationEntryImpl::UpdatePageState() { | |
| 262 // When we're using subframe entries, each FrameNavigationEntry has a | |
| 263 // frame-specific PageState. We combine these into an ExplodedPageState tree | |
| 264 // and generate a full PageState from it. | |
| 265 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries()); | |
| 266 ExplodedPageState exploded_state; | |
| 267 RecursivelyGenerateFrameState(frame_tree_.get(), &exploded_state.top, | |
| 268 &exploded_state.referenced_files); | |
| 269 | |
| 270 std::string encoded_data; | |
| 271 if (!EncodePageState(exploded_state, &encoded_data)) { | |
| 272 page_state_ = PageState(); | |
| 273 return; | |
| 274 } | |
| 275 | |
| 276 page_state_ = PageState::CreateFromEncodedData(encoded_data); | |
| 199 } | 277 } |
| 200 | 278 |
| 201 void NavigationEntryImpl::SetPageID(int page_id) { | 279 void NavigationEntryImpl::SetPageID(int page_id) { |
| 202 page_id_ = page_id; | 280 page_id_ = page_id; |
| 203 } | 281 } |
| 204 | 282 |
| 205 int32 NavigationEntryImpl::GetPageID() const { | 283 int32 NavigationEntryImpl::GetPageID() const { |
| 206 return page_id_; | 284 return page_id_; |
| 207 } | 285 } |
| 208 | 286 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 copy->ssl_ = ssl_; | 503 copy->ssl_ = ssl_; |
| 426 copy->transition_type_ = transition_type_; | 504 copy->transition_type_ = transition_type_; |
| 427 copy->user_typed_url_ = user_typed_url_; | 505 copy->user_typed_url_ = user_typed_url_; |
| 428 copy->has_post_data_ = has_post_data_; | 506 copy->has_post_data_ = has_post_data_; |
| 429 copy->post_id_ = post_id_; | 507 copy->post_id_ = post_id_; |
| 430 copy->restore_type_ = restore_type_; | 508 copy->restore_type_ = restore_type_; |
| 431 copy->original_request_url_ = original_request_url_; | 509 copy->original_request_url_ = original_request_url_; |
| 432 copy->is_overriding_user_agent_ = is_overriding_user_agent_; | 510 copy->is_overriding_user_agent_ = is_overriding_user_agent_; |
| 433 copy->timestamp_ = timestamp_; | 511 copy->timestamp_ = timestamp_; |
| 434 copy->http_status_code_ = http_status_code_; | 512 copy->http_status_code_ = http_status_code_; |
| 513 copy->page_state_ = page_state_; | |
| 435 // ResetForCommit: browser_initiated_post_data_ | 514 // ResetForCommit: browser_initiated_post_data_ |
| 436 copy->screenshot_ = screenshot_; | 515 copy->screenshot_ = screenshot_; |
| 437 copy->extra_headers_ = extra_headers_; | 516 copy->extra_headers_ = extra_headers_; |
| 438 // ResetForCommit: source_site_instance_ | 517 // ResetForCommit: source_site_instance_ |
| 439 copy->base_url_for_data_url_ = base_url_for_data_url_; | 518 copy->base_url_for_data_url_ = base_url_for_data_url_; |
| 440 // ResetForCommit: is_renderer_initiated_ | 519 // ResetForCommit: is_renderer_initiated_ |
| 441 copy->cached_display_title_ = cached_display_title_; | 520 copy->cached_display_title_ = cached_display_title_; |
| 442 // ResetForCommit: transferred_global_request_id_ | 521 // ResetForCommit: transferred_global_request_id_ |
| 443 // ResetForCommit: should_replace_entry_ | 522 // ResetForCommit: should_replace_entry_ |
| 444 copy->redirect_chain_ = redirect_chain_; | 523 copy->redirect_chain_ = redirect_chain_; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 int current_offset_to_send = current_history_list_offset; | 590 int current_offset_to_send = current_history_list_offset; |
| 512 int current_length_to_send = current_history_list_length; | 591 int current_length_to_send = current_history_list_length; |
| 513 if (should_clear_history_list()) { | 592 if (should_clear_history_list()) { |
| 514 // Set the history list related parameters to the same values a | 593 // Set the history list related parameters to the same values a |
| 515 // NavigationController would return before its first navigation. This will | 594 // NavigationController would return before its first navigation. This will |
| 516 // fully clear the RenderView's view of the session history. | 595 // fully clear the RenderView's view of the session history. |
| 517 pending_offset_to_send = -1; | 596 pending_offset_to_send = -1; |
| 518 current_offset_to_send = -1; | 597 current_offset_to_send = -1; |
| 519 current_length_to_send = 0; | 598 current_length_to_send = 0; |
| 520 } | 599 } |
| 600 | |
| 601 // Use the overall PageState in default Chrome, and send the frame's state in | |
| 602 // OOPIF modes. | |
| 603 PageState page_state = SiteIsolationPolicy::UseSubframeNavigationEntries() | |
| 604 ? frame_entry.page_state() | |
| 605 : GetPageState(); | |
| 606 | |
| 521 return RequestNavigationParams( | 607 return RequestNavigationParams( |
| 522 GetIsOverridingUserAgent(), redirects, GetCanLoadLocalResources(), | 608 GetIsOverridingUserAgent(), redirects, GetCanLoadLocalResources(), |
| 523 base::Time::Now(), frame_entry.page_state(), GetPageID(), GetUniqueID(), | 609 base::Time::Now(), page_state, GetPageID(), GetUniqueID(), |
| 524 is_same_document_history_load, has_committed_real_load, | 610 is_same_document_history_load, has_committed_real_load, |
| 525 intended_as_new_entry, pending_offset_to_send, current_offset_to_send, | 611 intended_as_new_entry, pending_offset_to_send, current_offset_to_send, |
| 526 current_length_to_send, should_clear_history_list()); | 612 current_length_to_send, should_clear_history_list()); |
| 527 } | 613 } |
| 528 | 614 |
| 529 void NavigationEntryImpl::ResetForCommit() { | 615 void NavigationEntryImpl::ResetForCommit() { |
| 530 // Any state that only matters when a navigation entry is pending should be | 616 // Any state that only matters when a navigation entry is pending should be |
| 531 // cleared here. | 617 // cleared here. |
| 532 // TODO(creis): This state should be moved to NavigationRequest once | 618 // TODO(creis): This state should be moved to NavigationRequest once |
| 533 // PlzNavigate is enabled. | 619 // PlzNavigate is enabled. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 640 return node; | 726 return node; |
| 641 } | 727 } |
| 642 // Enqueue any children and keep looking. | 728 // Enqueue any children and keep looking. |
| 643 for (auto& child : node->children) | 729 for (auto& child : node->children) |
| 644 work_queue.push(child); | 730 work_queue.push(child); |
| 645 } | 731 } |
| 646 return nullptr; | 732 return nullptr; |
| 647 } | 733 } |
| 648 | 734 |
| 649 } // namespace content | 735 } // namespace content |
| OLD | NEW |