| 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 "chrome/browser/history/history.h" | 9 #include "chrome/browser/history/history.h" |
| 10 #include "chrome/browser/history/history_service_factory.h" | 10 #include "chrome/browser/history/history_service_factory.h" |
| 11 #include "chrome/browser/history/top_sites.h" | 11 #include "chrome/browser/history/top_sites.h" |
| 12 #include "chrome/browser/instant/instant_loader.h" |
| 13 #include "chrome/browser/prerender/prerender_contents.h" |
| 14 #include "chrome/browser/prerender/prerender_manager.h" |
| 15 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
| 14 #include "content/public/browser/navigation_details.h" | 18 #include "content/public/browser/navigation_details.h" |
| 15 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
| 16 #include "content/public/browser/notification_details.h" | 20 #include "content/public/browser/notification_details.h" |
| 17 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
| 18 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
| 19 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/browser/web_contents_delegate.h" | 24 #include "content/public/browser/web_contents_delegate.h" |
| 21 #include "content/public/common/frame_navigate_params.h" | 25 #include "content/public/common/frame_navigate_params.h" |
| 22 | 26 |
| 27 #if !defined(OS_ANDROID) |
| 28 #include "chrome/browser/ui/browser.h" |
| 29 #include "chrome/browser/ui/browser_finder.h" |
| 30 #endif |
| 31 |
| 23 using content::NavigationEntry; | 32 using content::NavigationEntry; |
| 24 using content::WebContents; | 33 using content::WebContents; |
| 25 | 34 |
| 26 HistoryTabHelper::HistoryTabHelper(WebContents* web_contents) | 35 HistoryTabHelper::HistoryTabHelper(WebContents* web_contents) |
| 27 : content::WebContentsObserver(web_contents), | 36 : content::WebContentsObserver(web_contents), |
| 28 received_page_title_(false) { | 37 received_page_title_(false) { |
| 29 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, | 38 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
| 30 content::Source<WebContents>(web_contents)); | 39 content::Source<WebContents>(web_contents)); |
| 31 } | 40 } |
| 32 | 41 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // which WillNavigate[Main,Sub]Frame will do before this function is called. | 107 // which WillNavigate[Main,Sub]Frame will do before this function is called. |
| 99 if (!params.should_update_history) | 108 if (!params.should_update_history) |
| 100 return; | 109 return; |
| 101 | 110 |
| 102 // Most of the time, the displayURL matches the loaded URL, but for about: | 111 // Most of the time, the displayURL matches the loaded URL, but for about: |
| 103 // URLs, we use a data: URL as the real value. We actually want to save the | 112 // URLs, we use a data: URL as the real value. We actually want to save the |
| 104 // about: URL to the history db and keep the data: URL hidden. This is what | 113 // about: URL to the history db and keep the data: URL hidden. This is what |
| 105 // the WebContents' URL getter does. | 114 // the WebContents' URL getter does. |
| 106 const history::HistoryAddPageArgs& add_page_args = | 115 const history::HistoryAddPageArgs& add_page_args = |
| 107 CreateHistoryAddPageArgs(web_contents()->GetURL(), details, params); | 116 CreateHistoryAddPageArgs(web_contents()->GetURL(), details, params); |
| 108 if (!web_contents()->GetDelegate() || | 117 |
| 109 !web_contents()->GetDelegate()->ShouldAddNavigationToHistory( | 118 prerender::PrerenderManager* prerender_manager = |
| 110 add_page_args, details.type)) | 119 prerender::PrerenderManagerFactory::GetForProfile( |
| 120 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); |
| 121 if (prerender_manager) { |
| 122 prerender::PrerenderContents* prerender_contents = |
| 123 prerender_manager->GetPrerenderContents(web_contents()); |
| 124 if (prerender_contents) { |
| 125 prerender_contents->DidNavigate(add_page_args); |
| 126 return; |
| 127 } |
| 128 } |
| 129 |
| 130 InstantLoader* instant_loader = |
| 131 InstantLoader::FromWebContents(web_contents()); |
| 132 if (instant_loader) { |
| 133 instant_loader->DidNavigate(add_page_args); |
| 111 return; | 134 return; |
| 135 } |
| 136 |
| 137 #if !defined(OS_ANDROID) |
| 138 // Don't update history if this web contents isn't associatd with a tab. |
| 139 Browser* browser = browser::FindBrowserWithWebContents(web_contents()); |
| 140 if (!browser || browser->is_app()) |
| 141 return; |
| 142 #endif |
| 112 | 143 |
| 113 UpdateHistoryForNavigation(add_page_args); | 144 UpdateHistoryForNavigation(add_page_args); |
| 114 } | 145 } |
| 115 | 146 |
| 116 void HistoryTabHelper::Observe(int type, | 147 void HistoryTabHelper::Observe(int type, |
| 117 const content::NotificationSource& source, | 148 const content::NotificationSource& source, |
| 118 const content::NotificationDetails& details) { | 149 const content::NotificationDetails& details) { |
| 119 DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED); | 150 DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED); |
| 120 std::pair<content::NavigationEntry*, bool>* title = | 151 std::pair<content::NavigationEntry*, bool>* title = |
| 121 content::Details<std::pair<content::NavigationEntry*, bool> >( | 152 content::Details<std::pair<content::NavigationEntry*, bool> >( |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 HistoryService* hs = | 218 HistoryService* hs = |
| 188 HistoryServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); | 219 HistoryServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); |
| 189 if (hs) { | 220 if (hs) { |
| 190 NavigationEntry* entry = tab->GetController().GetLastCommittedEntry(); | 221 NavigationEntry* entry = tab->GetController().GetLastCommittedEntry(); |
| 191 if (entry) { | 222 if (entry) { |
| 192 hs->UpdateWithPageEndTime(tab, entry->GetPageID(), tab->GetURL(), | 223 hs->UpdateWithPageEndTime(tab, entry->GetPageID(), tab->GetURL(), |
| 193 base::Time::Now()); | 224 base::Time::Now()); |
| 194 } | 225 } |
| 195 } | 226 } |
| 196 } | 227 } |
| OLD | NEW |