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" |
(...skipping 12 matching lines...) Expand all Loading... |
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; |
29 using content::WebContents; | 29 using content::WebContents; |
30 | 30 |
31 DEFINE_WEB_CONTENTS_USER_DATA_KEY(HistoryTabHelper); | 31 DEFINE_WEB_CONTENTS_USER_DATA_KEY(HistoryTabHelper); |
32 | 32 |
| 33 namespace { |
| 34 |
| 35 // Referrer used for clicks on article suggestions on the NTP. |
| 36 const char kChromeContentSuggestionsReferrer[] = |
| 37 "https://www.googleapis.com/auth/chrome-content-suggestions"; |
| 38 |
| 39 } // namespace |
| 40 |
33 HistoryTabHelper::HistoryTabHelper(WebContents* web_contents) | 41 HistoryTabHelper::HistoryTabHelper(WebContents* web_contents) |
34 : content::WebContentsObserver(web_contents), | 42 : content::WebContentsObserver(web_contents), |
35 received_page_title_(false) { | 43 received_page_title_(false) { |
36 } | 44 } |
37 | 45 |
38 HistoryTabHelper::~HistoryTabHelper() { | 46 HistoryTabHelper::~HistoryTabHelper() { |
39 } | 47 } |
40 | 48 |
41 void HistoryTabHelper::UpdateHistoryForNavigation( | 49 void HistoryTabHelper::UpdateHistoryForNavigation( |
42 const history::HistoryAddPageArgs& add_page_args) { | 50 const history::HistoryAddPageArgs& add_page_args) { |
43 history::HistoryService* hs = GetHistoryService(); | 51 history::HistoryService* hs = GetHistoryService(); |
44 if (hs) | 52 if (hs) |
45 GetHistoryService()->AddPage(add_page_args); | 53 GetHistoryService()->AddPage(add_page_args); |
46 } | 54 } |
47 | 55 |
48 void HistoryTabHelper::UpdateHistoryPageTitle(const NavigationEntry& entry) { | 56 void HistoryTabHelper::UpdateHistoryPageTitle(const NavigationEntry& entry) { |
49 history::HistoryService* hs = GetHistoryService(); | 57 history::HistoryService* hs = GetHistoryService(); |
50 if (hs) | 58 if (hs) |
51 hs->SetPageTitle(entry.GetVirtualURL(), entry.GetTitleForDisplay()); | 59 hs->SetPageTitle(entry.GetVirtualURL(), entry.GetTitleForDisplay()); |
52 } | 60 } |
53 | 61 |
54 history::HistoryAddPageArgs | 62 history::HistoryAddPageArgs |
55 HistoryTabHelper::CreateHistoryAddPageArgs( | 63 HistoryTabHelper::CreateHistoryAddPageArgs( |
56 const GURL& virtual_url, | 64 const GURL& virtual_url, |
57 base::Time timestamp, | 65 base::Time timestamp, |
58 bool did_replace_entry, | 66 bool did_replace_entry, |
59 int nav_entry_id, | 67 int nav_entry_id, |
60 const content::FrameNavigateParams& params) { | 68 const content::FrameNavigateParams& params) { |
| 69 // Clicks on content suggestions on the NTP should not contribute to the |
| 70 // Most Visited tiles in the NTP. |
| 71 const bool consider_for_ntp_most_visited = |
| 72 params.referrer.url != GURL(kChromeContentSuggestionsReferrer); |
| 73 |
61 history::HistoryAddPageArgs add_page_args( | 74 history::HistoryAddPageArgs add_page_args( |
62 params.url, timestamp, history::ContextIDForWebContents(web_contents()), | 75 params.url, timestamp, history::ContextIDForWebContents(web_contents()), |
63 nav_entry_id, params.referrer.url, params.redirects, params.transition, | 76 nav_entry_id, params.referrer.url, params.redirects, params.transition, |
64 history::SOURCE_BROWSED, did_replace_entry); | 77 history::SOURCE_BROWSED, did_replace_entry, |
| 78 consider_for_ntp_most_visited); |
65 if (ui::PageTransitionIsMainFrame(params.transition) && | 79 if (ui::PageTransitionIsMainFrame(params.transition) && |
66 virtual_url != params.url) { | 80 virtual_url != params.url) { |
67 // Hack on the "virtual" URL so that it will appear in history. For some | 81 // Hack on the "virtual" URL so that it will appear in history. For some |
68 // types of URLs, we will display a magic URL that is different from where | 82 // types of URLs, we will display a magic URL that is different from where |
69 // the page is actually navigated. We want the user to see in history what | 83 // the page is actually navigated. We want the user to see in history what |
70 // they saw in the URL bar, so we add the virtual URL as a redirect. This | 84 // they saw in the URL bar, so we add the virtual URL as a redirect. This |
71 // only applies to the main frame, as the virtual URL doesn't apply to | 85 // only applies to the main frame, as the virtual URL doesn't apply to |
72 // sub-frames. | 86 // sub-frames. |
73 add_page_args.url = virtual_url; | 87 add_page_args.url = virtual_url; |
74 if (!add_page_args.redirects.empty()) | 88 if (!add_page_args.redirects.empty()) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 if (hs) { | 172 if (hs) { |
159 NavigationEntry* entry = tab->GetController().GetLastCommittedEntry(); | 173 NavigationEntry* entry = tab->GetController().GetLastCommittedEntry(); |
160 history::ContextID context_id = history::ContextIDForWebContents(tab); | 174 history::ContextID context_id = history::ContextIDForWebContents(tab); |
161 if (entry) { | 175 if (entry) { |
162 hs->UpdateWithPageEndTime(context_id, entry->GetUniqueID(), tab->GetURL(), | 176 hs->UpdateWithPageEndTime(context_id, entry->GetUniqueID(), tab->GetURL(), |
163 base::Time::Now()); | 177 base::Time::Now()); |
164 } | 178 } |
165 hs->ClearCachedDataForContextID(context_id); | 179 hs->ClearCachedDataForContextID(context_id); |
166 } | 180 } |
167 } | 181 } |
OLD | NEW |