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 /* | 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 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 pending_entry_->restore_type() != NavigationEntryImpl::RESTORE_NONE) | 819 pending_entry_->restore_type() != NavigationEntryImpl::RESTORE_NONE) |
820 pending_entry_->set_restore_type(NavigationEntryImpl::RESTORE_NONE); | 820 pending_entry_->set_restore_type(NavigationEntryImpl::RESTORE_NONE); |
821 | 821 |
822 // The renderer tells us whether the navigation replaces the current entry. | 822 // The renderer tells us whether the navigation replaces the current entry. |
823 details->did_replace_entry = params.should_replace_current_entry; | 823 details->did_replace_entry = params.should_replace_current_entry; |
824 | 824 |
825 // Do navigation-type specific actions. These will make and commit an entry. | 825 // Do navigation-type specific actions. These will make and commit an entry. |
826 details->type = ClassifyNavigation(rfh, params); | 826 details->type = ClassifyNavigation(rfh, params); |
827 | 827 |
828 // is_in_page must be computed before the entry gets committed. | 828 // is_in_page must be computed before the entry gets committed. |
829 details->is_in_page = IsURLInPageNavigation( | 829 details->is_in_page = IsURLInPageNavigation(params.url, params.origin, |
830 params.url, params.was_within_same_page, rfh); | 830 params.was_within_same_page, rfh); |
831 | 831 |
832 switch (details->type) { | 832 switch (details->type) { |
833 case NAVIGATION_TYPE_NEW_PAGE: | 833 case NAVIGATION_TYPE_NEW_PAGE: |
834 RendererDidNavigateToNewPage(rfh, params, details->did_replace_entry); | 834 RendererDidNavigateToNewPage(rfh, params, details->did_replace_entry); |
835 break; | 835 break; |
836 case NAVIGATION_TYPE_EXISTING_PAGE: | 836 case NAVIGATION_TYPE_EXISTING_PAGE: |
837 details->did_replace_entry = details->is_in_page; | 837 details->did_replace_entry = details->is_in_page; |
838 RendererDidNavigateToExistingPage(rfh, params); | 838 RendererDidNavigateToExistingPage(rfh, params); |
839 break; | 839 break; |
840 case NAVIGATION_TYPE_SAME_PAGE: | 840 case NAVIGATION_TYPE_SAME_PAGE: |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1365 // 2. A history API navigation (pushState and replaceState). This case is | 1365 // 2. A history API navigation (pushState and replaceState). This case is |
1366 // always in-page, but the urls are not guaranteed to match excluding the | 1366 // always in-page, but the urls are not guaranteed to match excluding the |
1367 // fragment. The relevant spec allows pushState/replaceState to any URL on | 1367 // fragment. The relevant spec allows pushState/replaceState to any URL on |
1368 // the same origin. | 1368 // the same origin. |
1369 // However, due to reloads, even identical urls are *not* guaranteed to be | 1369 // However, due to reloads, even identical urls are *not* guaranteed to be |
1370 // in-page navigations, we have to trust the renderer almost entirely. | 1370 // in-page navigations, we have to trust the renderer almost entirely. |
1371 // The one thing we do know is that cross-origin navigations will *never* be | 1371 // The one thing we do know is that cross-origin navigations will *never* be |
1372 // in-page. Therefore, trust the renderer if the URLs are on the same origin, | 1372 // in-page. Therefore, trust the renderer if the URLs are on the same origin, |
1373 // and assume the renderer is malicious if a cross-origin navigation claims to | 1373 // and assume the renderer is malicious if a cross-origin navigation claims to |
1374 // be in-page. | 1374 // be in-page. |
| 1375 // |
| 1376 // TODO(creis): Clean up and simplify the about:blank and origin checks below, |
| 1377 // which are likely redundant with each other. Be careful about data URLs vs |
| 1378 // about:blank, both of which are unique origins and thus not considered equal. |
1375 bool NavigationControllerImpl::IsURLInPageNavigation( | 1379 bool NavigationControllerImpl::IsURLInPageNavigation( |
1376 const GURL& url, | 1380 const GURL& url, |
| 1381 const url::Origin& origin, |
1377 bool renderer_says_in_page, | 1382 bool renderer_says_in_page, |
1378 RenderFrameHost* rfh) const { | 1383 RenderFrameHost* rfh) const { |
1379 RenderFrameHostImpl* rfhi = static_cast<RenderFrameHostImpl*>(rfh); | 1384 RenderFrameHostImpl* rfhi = static_cast<RenderFrameHostImpl*>(rfh); |
1380 GURL last_committed_url; | 1385 GURL last_committed_url; |
1381 if (rfh->GetParent()) { | 1386 if (rfh->GetParent()) { |
1382 // Use the FrameTreeNode's current_url and not rfh->GetLastCommittedURL(), | 1387 // Use the FrameTreeNode's current_url and not rfh->GetLastCommittedURL(), |
1383 // which might be empty in a new RenderFrameHost after a process swap. | 1388 // which might be empty in a new RenderFrameHost after a process swap. |
1384 // Here, we care about the last committed URL in the FrameTreeNode, | 1389 // Here, we care about the last committed URL in the FrameTreeNode, |
1385 // regardless of which process it is in. | 1390 // regardless of which process it is in. |
1386 last_committed_url = rfhi->frame_tree_node()->current_url(); | 1391 last_committed_url = rfhi->frame_tree_node()->current_url(); |
(...skipping 12 matching lines...) Expand all Loading... |
1399 rfhi->frame_tree_node()->current_origin(); | 1404 rfhi->frame_tree_node()->current_origin(); |
1400 bool is_same_origin = last_committed_url.is_empty() || | 1405 bool is_same_origin = last_committed_url.is_empty() || |
1401 // TODO(japhet): We should only permit navigations | 1406 // TODO(japhet): We should only permit navigations |
1402 // originating from about:blank to be in-page if the | 1407 // originating from about:blank to be in-page if the |
1403 // about:blank is the first document that frame loaded. | 1408 // about:blank is the first document that frame loaded. |
1404 // We don't have sufficient information to identify | 1409 // We don't have sufficient information to identify |
1405 // that case at the moment, so always allow about:blank | 1410 // that case at the moment, so always allow about:blank |
1406 // for now. | 1411 // for now. |
1407 last_committed_url == GURL(url::kAboutBlankURL) || | 1412 last_committed_url == GURL(url::kAboutBlankURL) || |
1408 last_committed_url.GetOrigin() == url.GetOrigin() || | 1413 last_committed_url.GetOrigin() == url.GetOrigin() || |
| 1414 committed_origin == origin || |
1409 !prefs.web_security_enabled || | 1415 !prefs.web_security_enabled || |
1410 (prefs.allow_universal_access_from_file_urls && | 1416 (prefs.allow_universal_access_from_file_urls && |
1411 committed_origin.scheme() == url::kFileScheme); | 1417 committed_origin.scheme() == url::kFileScheme); |
1412 if (!is_same_origin && renderer_says_in_page) { | 1418 if (!is_same_origin && renderer_says_in_page) { |
1413 bad_message::ReceivedBadMessage(rfh->GetProcess(), | 1419 bad_message::ReceivedBadMessage(rfh->GetProcess(), |
1414 bad_message::NC_IN_PAGE_NAVIGATION); | 1420 bad_message::NC_IN_PAGE_NAVIGATION); |
1415 } | 1421 } |
1416 return is_same_origin && renderer_says_in_page; | 1422 return is_same_origin && renderer_says_in_page; |
1417 } | 1423 } |
1418 | 1424 |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2066 } | 2072 } |
2067 } | 2073 } |
2068 } | 2074 } |
2069 | 2075 |
2070 void NavigationControllerImpl::SetGetTimestampCallbackForTest( | 2076 void NavigationControllerImpl::SetGetTimestampCallbackForTest( |
2071 const base::Callback<base::Time()>& get_timestamp_callback) { | 2077 const base::Callback<base::Time()>& get_timestamp_callback) { |
2072 get_timestamp_callback_ = get_timestamp_callback; | 2078 get_timestamp_callback_ = get_timestamp_callback; |
2073 } | 2079 } |
2074 | 2080 |
2075 } // namespace content | 2081 } // namespace content |
OLD | NEW |