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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). | 38 // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). |
| 39 int GetUniqueIDInConstructor() { | 39 int GetUniqueIDInConstructor() { |
| 40 static int unique_id_counter = 0; | 40 static int unique_id_counter = 0; |
| 41 return ++unique_id_counter; | 41 return ++unique_id_counter; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void RecursivelyGenerateFrameEntries( | 44 void RecursivelyGenerateFrameEntries( |
| 45 const ExplodedFrameState& state, | 45 const ExplodedFrameState& state, |
| 46 const std::vector<base::NullableString16>& referenced_files, | 46 const std::vector<base::NullableString16>& referenced_files, |
| 47 NavigationEntryImpl::TreeNode* node) { | 47 NavigationEntryImpl::TreeNode* node) { |
| 48 GURL renderer_url(state.url_string.string()); | |
| 49 bool is_srcdoc = (renderer_url == GURL(content::kAboutSrcDocURL)); | |
| 50 GURL browser_url = is_srcdoc ? GURL(url::kAboutBlankURL) : renderer_url; | |
| 51 | |
| 48 node->frame_entry = new FrameNavigationEntry( | 52 node->frame_entry = new FrameNavigationEntry( |
| 49 UTF16ToUTF8(state.target.string()), state.item_sequence_number, | 53 UTF16ToUTF8(state.target.string()), state.item_sequence_number, |
| 50 state.document_sequence_number, nullptr, nullptr, | 54 state.document_sequence_number, nullptr, nullptr, browser_url, |
| 51 GURL(state.url_string.string()), | 55 Referrer(GURL(state.referrer.string()), state.referrer_policy), "GET", -1, |
| 52 Referrer(GURL(state.referrer.string()), state.referrer_policy), "GET", | 56 is_srcdoc); |
| 53 -1); | |
| 54 | 57 |
| 55 // Set a single-frame PageState on the entry. | 58 // Set a single-frame PageState on the entry. |
| 56 ExplodedPageState page_state; | 59 ExplodedPageState page_state; |
| 57 | 60 |
| 58 // Copy the incoming PageState's list of referenced files into the main | 61 // Copy the incoming PageState's list of referenced files into the main |
| 59 // frame's PageState. (We don't pass the list to subframes below.) | 62 // frame's PageState. (We don't pass the list to subframes below.) |
| 60 // TODO(creis): Grant access to this list for each process that renders | 63 // TODO(creis): Grant access to this list for each process that renders |
| 61 // this page, even for OOPIFs. Eventually keep track of a verified list of | 64 // this page, even for OOPIFs. Eventually keep track of a verified list of |
| 62 // files per frame, so that we only grant access to processes that need it. | 65 // files per frame, so that we only grant access to processes that need it. |
| 63 if (referenced_files.size() > 0) | 66 if (referenced_files.size() > 0) |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 bool is_renderer_initiated) | 256 bool is_renderer_initiated) |
| 254 : frame_tree_(new TreeNode(nullptr, | 257 : frame_tree_(new TreeNode(nullptr, |
| 255 new FrameNavigationEntry("", | 258 new FrameNavigationEntry("", |
| 256 -1, | 259 -1, |
| 257 -1, | 260 -1, |
| 258 std::move(instance), | 261 std::move(instance), |
| 259 nullptr, | 262 nullptr, |
| 260 url, | 263 url, |
| 261 referrer, | 264 referrer, |
| 262 "GET", | 265 "GET", |
| 263 -1))), | 266 -1, |
| 267 false))), | |
| 264 unique_id_(GetUniqueIDInConstructor()), | 268 unique_id_(GetUniqueIDInConstructor()), |
| 265 bindings_(kInvalidBindings), | 269 bindings_(kInvalidBindings), |
| 266 page_type_(PAGE_TYPE_NORMAL), | 270 page_type_(PAGE_TYPE_NORMAL), |
| 267 update_virtual_url_with_url_(false), | 271 update_virtual_url_with_url_(false), |
| 268 title_(title), | 272 title_(title), |
| 269 transition_type_(transition_type), | 273 transition_type_(transition_type), |
| 270 restore_type_(RestoreType::NONE), | 274 restore_type_(RestoreType::NONE), |
| 271 is_overriding_user_agent_(false), | 275 is_overriding_user_agent_(false), |
| 272 http_status_code_(0), | 276 http_status_code_(0), |
| 273 is_renderer_initiated_(is_renderer_initiated), | 277 is_renderer_initiated_(is_renderer_initiated), |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 FrameTreeNode* frame_tree_node, | 795 FrameTreeNode* frame_tree_node, |
| 792 int64_t item_sequence_number, | 796 int64_t item_sequence_number, |
| 793 int64_t document_sequence_number, | 797 int64_t document_sequence_number, |
| 794 SiteInstanceImpl* site_instance, | 798 SiteInstanceImpl* site_instance, |
| 795 scoped_refptr<SiteInstanceImpl> source_site_instance, | 799 scoped_refptr<SiteInstanceImpl> source_site_instance, |
| 796 const GURL& url, | 800 const GURL& url, |
| 797 const Referrer& referrer, | 801 const Referrer& referrer, |
| 798 const std::vector<GURL>& redirect_chain, | 802 const std::vector<GURL>& redirect_chain, |
| 799 const PageState& page_state, | 803 const PageState& page_state, |
| 800 const std::string& method, | 804 const std::string& method, |
| 801 int64_t post_id) { | 805 int64_t post_id, |
| 806 bool is_srcdoc) { | |
| 802 // If this is called for the main frame, the FrameNavigationEntry is | 807 // If this is called for the main frame, the FrameNavigationEntry is |
| 803 // guaranteed to exist, so just update it directly and return. | 808 // guaranteed to exist, so just update it directly and return. |
| 804 if (frame_tree_node->IsMainFrame()) { | 809 if (frame_tree_node->IsMainFrame()) { |
| 805 // If the document of the FrameNavigationEntry is changing, we must clear | 810 // If the document of the FrameNavigationEntry is changing, we must clear |
| 806 // any child FrameNavigationEntries. | 811 // any child FrameNavigationEntries. |
| 807 if (root_node()->frame_entry->document_sequence_number() != | 812 if (root_node()->frame_entry->document_sequence_number() != |
| 808 document_sequence_number) | 813 document_sequence_number) |
| 809 root_node()->children.clear(); | 814 root_node()->children.clear(); |
| 810 | 815 |
| 811 root_node()->frame_entry->UpdateEntry( | 816 root_node()->frame_entry->UpdateEntry( |
| 812 frame_tree_node->unique_name(), item_sequence_number, | 817 frame_tree_node->unique_name(), item_sequence_number, |
| 813 document_sequence_number, site_instance, | 818 document_sequence_number, site_instance, |
| 814 std::move(source_site_instance), url, referrer, redirect_chain, | 819 std::move(source_site_instance), url, referrer, redirect_chain, |
| 815 page_state, method, post_id); | 820 page_state, method, post_id, is_srcdoc); |
| 816 return; | 821 return; |
| 817 } | 822 } |
| 818 | 823 |
| 819 // We should already have a TreeNode for the parent node by the time this node | 824 // We should already have a TreeNode for the parent node by the time this node |
| 820 // commits. Find it first. | 825 // commits. Find it first. |
| 821 NavigationEntryImpl::TreeNode* parent_node = | 826 NavigationEntryImpl::TreeNode* parent_node = |
| 822 FindFrameEntry(frame_tree_node->parent()); | 827 FindFrameEntry(frame_tree_node->parent()); |
| 823 if (!parent_node) { | 828 if (!parent_node) { |
| 824 // The renderer should not send a commit for a subframe before its parent. | 829 // The renderer should not send a commit for a subframe before its parent. |
| 825 // TODO(creis): Kill the renderer if we get here. | 830 // TODO(creis): Kill the renderer if we get here. |
| 826 return; | 831 return; |
| 827 } | 832 } |
| 828 | 833 |
| 829 // Now check whether we have a TreeNode for the node itself. | 834 // Now check whether we have a TreeNode for the node itself. |
| 830 const std::string& unique_name = frame_tree_node->unique_name(); | 835 const std::string& unique_name = frame_tree_node->unique_name(); |
| 831 for (TreeNode* child : parent_node->children) { | 836 for (TreeNode* child : parent_node->children) { |
| 832 if (child->frame_entry->frame_unique_name() == unique_name) { | 837 if (child->frame_entry->frame_unique_name() == unique_name) { |
| 833 // If the document of the FrameNavigationEntry is changing, we must clear | 838 // If the document of the FrameNavigationEntry is changing, we must clear |
| 834 // any child FrameNavigationEntries. | 839 // any child FrameNavigationEntries. |
| 835 if (child->frame_entry->document_sequence_number() != | 840 if (child->frame_entry->document_sequence_number() != |
| 836 document_sequence_number) | 841 document_sequence_number) |
| 837 child->children.clear(); | 842 child->children.clear(); |
| 838 | 843 |
| 839 // Update the existing FrameNavigationEntry (e.g., for replaceState). | 844 // Update the existing FrameNavigationEntry (e.g., for replaceState). |
| 840 child->frame_entry->UpdateEntry( | 845 child->frame_entry->UpdateEntry( |
| 841 unique_name, item_sequence_number, document_sequence_number, | 846 unique_name, item_sequence_number, document_sequence_number, |
| 842 site_instance, std::move(source_site_instance), url, referrer, | 847 site_instance, std::move(source_site_instance), url, referrer, |
| 843 redirect_chain, page_state, method, post_id); | 848 redirect_chain, page_state, method, post_id, is_srcdoc); |
| 844 return; | 849 return; |
| 845 } | 850 } |
| 846 } | 851 } |
| 847 | 852 |
| 848 // No entry exists yet, so create a new one. | 853 // No entry exists yet, so create a new one. |
| 849 // Unordered list, since we expect to look up entries by frame sequence number | 854 // Unordered list, since we expect to look up entries by frame sequence number |
| 850 // or unique name. | 855 // or unique name. |
| 851 FrameNavigationEntry* frame_entry = new FrameNavigationEntry( | 856 FrameNavigationEntry* frame_entry = new FrameNavigationEntry( |
| 852 unique_name, item_sequence_number, document_sequence_number, | 857 unique_name, item_sequence_number, document_sequence_number, |
| 853 site_instance, std::move(source_site_instance), url, referrer, method, | 858 site_instance, std::move(source_site_instance), url, referrer, method, |
| 854 post_id); | 859 post_id, is_srcdoc); |
| 855 frame_entry->SetPageState(page_state); | 860 frame_entry->SetPageState(page_state); |
| 856 frame_entry->set_redirect_chain(redirect_chain); | 861 frame_entry->set_redirect_chain(redirect_chain); |
| 857 parent_node->children.push_back( | 862 parent_node->children.push_back( |
| 858 new NavigationEntryImpl::TreeNode(parent_node, frame_entry)); | 863 new NavigationEntryImpl::TreeNode(parent_node, frame_entry)); |
| 859 } | 864 } |
| 860 | 865 |
| 861 FrameNavigationEntry* NavigationEntryImpl::GetFrameEntry( | 866 FrameNavigationEntry* NavigationEntryImpl::GetFrameEntry( |
| 862 FrameTreeNode* frame_tree_node) const { | 867 FrameTreeNode* frame_tree_node) const { |
| 863 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); | 868 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); |
| 864 return tree_node ? tree_node->frame_entry.get() : nullptr; | 869 return tree_node ? tree_node->frame_entry.get() : nullptr; |
| 865 } | 870 } |
| 866 | 871 |
| 867 std::map<std::string, bool> NavigationEntryImpl::GetSubframeUniqueNames( | 872 std::map<std::string, bool> NavigationEntryImpl::GetSubframeUniqueNames( |
| 868 FrameTreeNode* frame_tree_node) const { | 873 FrameTreeNode* frame_tree_node) const { |
| 869 std::map<std::string, bool> names; | 874 std::map<std::string, bool> names; |
| 870 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); | 875 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); |
| 871 if (tree_node) { | 876 if (tree_node) { |
| 872 // Return the names of all immediate children. | 877 // Return the names of all immediate children. |
| 873 for (TreeNode* child : tree_node->children) { | 878 for (TreeNode* child : tree_node->children) { |
| 874 // Keep track of whether we would be loading about:blank, since the | 879 // Keep track of whether we would be loading about:blank, since the |
| 875 // renderer should be allowed to just commit the initial blank frame if | 880 // renderer should be allowed to just commit the initial blank frame if |
| 876 // that was the default URL. PageState doesn't matter there, because | 881 // that was the default URL. PageState doesn't matter there, because |
| 877 // content injected into about:blank frames doesn't use it. | 882 // content injected into about:blank frames doesn't use it. |
| 878 // | 883 // |
| 879 // Be careful not to include iframe srcdoc URLs in this check, which do | 884 // Be careful not to include iframe srcdoc URLs in this check, which do |
|
Charlie Reis
2016/11/07 21:32:58
Note: This code also depended on detecting the src
arthursonzogni
2016/11/08 12:21:30
Yes, this code could be cleaned here by the two ap
| |
| 880 // need their PageState. The committed URL in that case gets rewritten to | 885 // need their PageState. The committed URL in that case gets rewritten to |
| 881 // about:blank, but we can detect it via the PageState's URL. | 886 // about:blank, but we can detect it via the PageState's URL. |
| 882 // | 887 // |
| 883 // See https://crbug.com/657896 for details. | 888 // See https://crbug.com/657896 for details. |
| 884 bool is_about_blank = false; | 889 bool is_about_blank = false; |
| 885 ExplodedPageState exploded_page_state; | 890 ExplodedPageState exploded_page_state; |
| 886 if (DecodePageState(child->frame_entry->page_state().ToEncodedData(), | 891 if (DecodePageState(child->frame_entry->page_state().ToEncodedData(), |
| 887 &exploded_page_state)) { | 892 &exploded_page_state)) { |
| 888 ExplodedFrameState frame_state = exploded_page_state.top; | 893 ExplodedFrameState frame_state = exploded_page_state.top; |
| 889 if (UTF16ToUTF8(frame_state.url_string.string()) == url::kAboutBlankURL) | 894 if (UTF16ToUTF8(frame_state.url_string.string()) == url::kAboutBlankURL) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 956 return node; | 961 return node; |
| 957 | 962 |
| 958 // Enqueue any children and keep looking. | 963 // Enqueue any children and keep looking. |
| 959 for (auto* child : node->children) | 964 for (auto* child : node->children) |
| 960 work_queue.push(child); | 965 work_queue.push(child); |
| 961 } | 966 } |
| 962 return nullptr; | 967 return nullptr; |
| 963 } | 968 } |
| 964 | 969 |
| 965 } // namespace content | 970 } // namespace content |
| OLD | NEW |