| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/history/history_tab_helper.h" | 5 #include "chrome/browser/history/history_tab_helper.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/history/history_service_factory.h" | 10 #include "chrome/browser/history/history_service_factory.h" |
| 11 #include "chrome/browser/prerender/prerender_contents.h" | 11 #include "chrome/browser/prerender/prerender_contents.h" |
| 12 #include "chrome/browser/prerender/prerender_manager.h" | 12 #include "chrome/browser/prerender/prerender_manager.h" |
| 13 #include "chrome/browser/prerender/prerender_manager_factory.h" | 13 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "components/history/content/browser/history_context_helper.h" | 15 #include "components/history/content/browser/history_context_helper.h" |
| 16 #include "components/history/core/browser/history_service.h" | 16 #include "components/history/core/browser/history_service.h" |
| 17 #include "content/public/browser/navigation_details.h" | |
| 18 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
| 18 #include "content/public/browser/navigation_handle.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/browser/web_contents_delegate.h" | 20 #include "content/public/browser/web_contents_delegate.h" |
| 21 #include "content/public/common/frame_navigate_params.h" | 21 #include "content/public/common/frame_navigate_params.h" |
| 22 | 22 |
| 23 #if !defined(OS_ANDROID) | 23 #if !defined(OS_ANDROID) |
| 24 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 using content::NavigationEntry; | 28 using content::NavigationEntry; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 56 void HistoryTabHelper::UpdateHistoryPageTitle(const NavigationEntry& entry) { | 56 void HistoryTabHelper::UpdateHistoryPageTitle(const NavigationEntry& entry) { |
| 57 history::HistoryService* hs = GetHistoryService(); | 57 history::HistoryService* hs = GetHistoryService(); |
| 58 if (hs) | 58 if (hs) |
| 59 hs->SetPageTitle(entry.GetVirtualURL(), entry.GetTitleForDisplay()); | 59 hs->SetPageTitle(entry.GetVirtualURL(), entry.GetTitleForDisplay()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 history::HistoryAddPageArgs | 62 history::HistoryAddPageArgs |
| 63 HistoryTabHelper::CreateHistoryAddPageArgs( | 63 HistoryTabHelper::CreateHistoryAddPageArgs( |
| 64 const GURL& virtual_url, | 64 const GURL& virtual_url, |
| 65 base::Time timestamp, | 65 base::Time timestamp, |
| 66 bool did_replace_entry, | |
| 67 int nav_entry_id, | 66 int nav_entry_id, |
| 68 const content::FrameNavigateParams& params) { | 67 content::NavigationHandle* navigation_handle) { |
| 69 // Clicks on content suggestions on the NTP should not contribute to the | 68 // Clicks on content suggestions on the NTP should not contribute to the |
| 70 // Most Visited tiles in the NTP. | 69 // Most Visited tiles in the NTP. |
| 71 const bool consider_for_ntp_most_visited = | 70 const bool consider_for_ntp_most_visited = |
| 72 params.referrer.url != kChromeContentSuggestionsReferrer; | 71 navigation_handle->GetReferrer().url != kChromeContentSuggestionsReferrer; |
| 73 | 72 |
| 74 history::HistoryAddPageArgs add_page_args( | 73 history::HistoryAddPageArgs add_page_args( |
| 75 params.url, timestamp, history::ContextIDForWebContents(web_contents()), | 74 navigation_handle->GetURL(), timestamp, |
| 76 nav_entry_id, params.referrer.url, params.redirects, params.transition, | 75 history::ContextIDForWebContents(web_contents()), |
| 77 history::SOURCE_BROWSED, did_replace_entry, | 76 nav_entry_id, navigation_handle->GetReferrer().url, |
| 78 consider_for_ntp_most_visited); | 77 navigation_handle->GetRedirectChain(), |
| 79 if (ui::PageTransitionIsMainFrame(params.transition) && | 78 navigation_handle->GetPageTransition(), history::SOURCE_BROWSED, |
| 80 virtual_url != params.url) { | 79 navigation_handle->DidReplaceEntry(), consider_for_ntp_most_visited); |
| 80 if (ui::PageTransitionIsMainFrame(navigation_handle->GetPageTransition()) && |
| 81 virtual_url != navigation_handle->GetURL()) { |
| 81 // Hack on the "virtual" URL so that it will appear in history. For some | 82 // Hack on the "virtual" URL so that it will appear in history. For some |
| 82 // types of URLs, we will display a magic URL that is different from where | 83 // types of URLs, we will display a magic URL that is different from where |
| 83 // the page is actually navigated. We want the user to see in history what | 84 // the page is actually navigated. We want the user to see in history what |
| 84 // they saw in the URL bar, so we add the virtual URL as a redirect. This | 85 // they saw in the URL bar, so we add the virtual URL as a redirect. This |
| 85 // only applies to the main frame, as the virtual URL doesn't apply to | 86 // only applies to the main frame, as the virtual URL doesn't apply to |
| 86 // sub-frames. | 87 // sub-frames. |
| 87 add_page_args.url = virtual_url; | 88 add_page_args.url = virtual_url; |
| 88 if (!add_page_args.redirects.empty()) | 89 if (!add_page_args.redirects.empty()) |
| 89 add_page_args.redirects.back() = virtual_url; | 90 add_page_args.redirects.back() = virtual_url; |
| 90 } | 91 } |
| 91 return add_page_args; | 92 return add_page_args; |
| 92 } | 93 } |
| 93 | 94 |
| 94 void HistoryTabHelper::DidNavigateMainFrame( | 95 void HistoryTabHelper::DidFinishNavigation( |
| 95 const content::LoadCommittedDetails& details, | 96 content::NavigationHandle* navigation_handle) { |
| 96 const content::FrameNavigateParams& params) { | 97 if (!navigation_handle->HasCommitted()) |
| 97 // Allow the new page to set the title again. | 98 return; |
| 98 received_page_title_ = false; | |
| 99 } | |
| 100 | 99 |
| 101 void HistoryTabHelper::DidNavigateAnyFrame( | 100 if (navigation_handle->IsInMainFrame()) { |
| 102 content::RenderFrameHost* render_frame_host, | 101 // Allow the new page to set the title again. |
| 103 const content::LoadCommittedDetails& details, | 102 received_page_title_ = false; |
| 104 const content::FrameNavigateParams& params) { | 103 } |
| 104 |
| 105 // Update history. Note that this needs to happen after the entry is complete, | 105 // Update history. Note that this needs to happen after the entry is complete, |
| 106 // which WillNavigate[Main,Sub]Frame will do before this function is called. | 106 // which WillNavigate[Main,Sub]Frame will do before this function is called. |
| 107 if (!params.should_update_history) | 107 if (!navigation_handle->ShouldUpdateHistory()) |
| 108 return; | 108 return; |
| 109 | 109 |
| 110 // Most of the time, the displayURL matches the loaded URL, but for about: | 110 // Most of the time, the displayURL matches the loaded URL, but for about: |
| 111 // URLs, we use a data: URL as the real value. We actually want to save the | 111 // URLs, we use a data: URL as the real value. We actually want to save the |
| 112 // about: URL to the history db and keep the data: URL hidden. This is what | 112 // about: URL to the history db and keep the data: URL hidden. This is what |
| 113 // the WebContents' URL getter does. | 113 // the WebContents' URL getter does. |
| 114 NavigationEntry* last_committed = | 114 NavigationEntry* last_committed = |
| 115 web_contents()->GetController().GetLastCommittedEntry(); | 115 web_contents()->GetController().GetLastCommittedEntry(); |
| 116 const history::HistoryAddPageArgs& add_page_args = | 116 const history::HistoryAddPageArgs& add_page_args = |
| 117 CreateHistoryAddPageArgs( | 117 CreateHistoryAddPageArgs( |
| 118 web_contents()->GetURL(), details.entry->GetTimestamp(), | 118 web_contents()->GetURL(), last_committed->GetTimestamp(), |
| 119 details.did_replace_entry, last_committed->GetUniqueID(), params); | 119 last_committed->GetUniqueID(), navigation_handle); |
| 120 | 120 |
| 121 prerender::PrerenderManager* prerender_manager = | 121 prerender::PrerenderManager* prerender_manager = |
| 122 prerender::PrerenderManagerFactory::GetForBrowserContext( | 122 prerender::PrerenderManagerFactory::GetForBrowserContext( |
| 123 web_contents()->GetBrowserContext()); | 123 web_contents()->GetBrowserContext()); |
| 124 if (prerender_manager) { | 124 if (prerender_manager) { |
| 125 prerender::PrerenderContents* prerender_contents = | 125 prerender::PrerenderContents* prerender_contents = |
| 126 prerender_manager->GetPrerenderContents(web_contents()); | 126 prerender_manager->GetPrerenderContents(web_contents()); |
| 127 if (prerender_contents) { | 127 if (prerender_contents) { |
| 128 prerender_contents->DidNavigate(add_page_args); | 128 prerender_contents->DidNavigate(add_page_args); |
| 129 return; | 129 return; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 if (hs) { | 172 if (hs) { |
| 173 NavigationEntry* entry = tab->GetController().GetLastCommittedEntry(); | 173 NavigationEntry* entry = tab->GetController().GetLastCommittedEntry(); |
| 174 history::ContextID context_id = history::ContextIDForWebContents(tab); | 174 history::ContextID context_id = history::ContextIDForWebContents(tab); |
| 175 if (entry) { | 175 if (entry) { |
| 176 hs->UpdateWithPageEndTime(context_id, entry->GetUniqueID(), tab->GetURL(), | 176 hs->UpdateWithPageEndTime(context_id, entry->GetUniqueID(), tab->GetURL(), |
| 177 base::Time::Now()); | 177 base::Time::Now()); |
| 178 } | 178 } |
| 179 hs->ClearCachedDataForContextID(context_id); | 179 hs->ClearCachedDataForContextID(context_id); |
| 180 } | 180 } |
| 181 } | 181 } |
| OLD | NEW |