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/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
14 #include "content/public/browser/navigation_details.h" | 14 #include "content/public/browser/navigation_details.h" |
15 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
16 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
17 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
18 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 19 #include "content/public/browser/web_contents.h" |
19 #include "content/public/browser/web_contents_delegate.h" | 20 #include "content/public/browser/web_contents_delegate.h" |
20 #include "content/public/browser/web_contents.h" | |
21 #include "content/public/common/frame_navigate_params.h" | 21 #include "content/public/common/frame_navigate_params.h" |
22 | 22 |
23 using content::NavigationEntry; | 23 using content::NavigationEntry; |
24 using content::WebContents; | 24 using content::WebContents; |
25 | 25 |
26 HistoryTabHelper::HistoryTabHelper(WebContents* web_contents) | 26 HistoryTabHelper::HistoryTabHelper(WebContents* web_contents) |
27 : content::WebContentsObserver(web_contents), | 27 : content::WebContentsObserver(web_contents), |
28 received_page_title_(false) { | 28 received_page_title_(false) { |
29 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, | 29 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
30 content::Source<WebContents>(web_contents)); | 30 content::Source<WebContents>(web_contents)); |
31 } | 31 } |
32 | 32 |
33 HistoryTabHelper::~HistoryTabHelper() { | 33 HistoryTabHelper::~HistoryTabHelper() { |
34 } | 34 } |
35 | 35 |
36 void HistoryTabHelper::UpdateHistoryForNavigation( | 36 void HistoryTabHelper::UpdateHistoryForNavigation( |
37 scoped_refptr<history::HistoryAddPageArgs> add_page_args) { | 37 const history::HistoryAddPageArgs& add_page_args) { |
38 HistoryService* hs = GetHistoryService(); | 38 HistoryService* hs = GetHistoryService(); |
39 if (hs) | 39 if (hs) |
40 GetHistoryService()->AddPage(*add_page_args); | 40 GetHistoryService()->AddPage(add_page_args); |
41 } | 41 } |
42 | 42 |
43 void HistoryTabHelper::UpdateHistoryPageTitle(const NavigationEntry& entry) { | 43 void HistoryTabHelper::UpdateHistoryPageTitle(const NavigationEntry& entry) { |
44 HistoryService* hs = GetHistoryService(); | 44 HistoryService* hs = GetHistoryService(); |
45 if (hs) | 45 if (hs) |
46 hs->SetPageTitle(entry.GetVirtualURL(), entry.GetTitleForDisplay("")); | 46 hs->SetPageTitle(entry.GetVirtualURL(), entry.GetTitleForDisplay("")); |
47 } | 47 } |
48 | 48 |
49 scoped_refptr<history::HistoryAddPageArgs> | 49 history::HistoryAddPageArgs |
50 HistoryTabHelper::CreateHistoryAddPageArgs( | 50 HistoryTabHelper::CreateHistoryAddPageArgs( |
51 const GURL& virtual_url, | 51 const GURL& virtual_url, |
52 const content::LoadCommittedDetails& details, | 52 const content::LoadCommittedDetails& details, |
53 const content::FrameNavigateParams& params) { | 53 const content::FrameNavigateParams& params) { |
54 scoped_refptr<history::HistoryAddPageArgs> add_page_args( | 54 // TODO(akalin): Use the timestamp from details.entry when it |
55 new history::HistoryAddPageArgs( | 55 // becomes available. |
56 params.url, base::Time::Now(), web_contents(), params.page_id, | 56 const base::Time time = base::Time::Now(); |
| 57 history::HistoryAddPageArgs add_page_args( |
| 58 params.url, time, web_contents(), params.page_id, |
57 params.referrer.url, params.redirects, params.transition, | 59 params.referrer.url, params.redirects, params.transition, |
58 history::SOURCE_BROWSED, details.did_replace_entry)); | 60 history::SOURCE_BROWSED, details.did_replace_entry); |
59 if (content::PageTransitionIsMainFrame(params.transition) && | 61 if (content::PageTransitionIsMainFrame(params.transition) && |
60 virtual_url != params.url) { | 62 virtual_url != params.url) { |
61 // Hack on the "virtual" URL so that it will appear in history. For some | 63 // Hack on the "virtual" URL so that it will appear in history. For some |
62 // types of URLs, we will display a magic URL that is different from where | 64 // types of URLs, we will display a magic URL that is different from where |
63 // the page is actually navigated. We want the user to see in history what | 65 // the page is actually navigated. We want the user to see in history what |
64 // they saw in the URL bar, so we add the virtual URL as a redirect. This | 66 // they saw in the URL bar, so we add the virtual URL as a redirect. This |
65 // only applies to the main frame, as the virtual URL doesn't apply to | 67 // only applies to the main frame, as the virtual URL doesn't apply to |
66 // sub-frames. | 68 // sub-frames. |
67 add_page_args->url = virtual_url; | 69 add_page_args.url = virtual_url; |
68 if (!add_page_args->redirects.empty()) | 70 if (!add_page_args.redirects.empty()) |
69 add_page_args->redirects.back() = virtual_url; | 71 add_page_args.redirects.back() = virtual_url; |
70 } | 72 } |
71 return add_page_args; | 73 return add_page_args; |
72 } | 74 } |
73 | 75 |
74 bool HistoryTabHelper::OnMessageReceived(const IPC::Message& message) { | 76 bool HistoryTabHelper::OnMessageReceived(const IPC::Message& message) { |
75 bool handled = true; | 77 bool handled = true; |
76 IPC_BEGIN_MESSAGE_MAP(HistoryTabHelper, message) | 78 IPC_BEGIN_MESSAGE_MAP(HistoryTabHelper, message) |
77 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PageContents, OnPageContents) | 79 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PageContents, OnPageContents) |
78 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_Thumbnail, OnThumbnail) | 80 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_Thumbnail, OnThumbnail) |
79 IPC_MESSAGE_UNHANDLED(handled = false) | 81 IPC_MESSAGE_UNHANDLED(handled = false) |
(...skipping 14 matching lines...) Expand all Loading... |
94 const content::FrameNavigateParams& params) { | 96 const content::FrameNavigateParams& params) { |
95 // Update history. Note that this needs to happen after the entry is complete, | 97 // Update history. Note that this needs to happen after the entry is complete, |
96 // which WillNavigate[Main,Sub]Frame will do before this function is called. | 98 // which WillNavigate[Main,Sub]Frame will do before this function is called. |
97 if (!params.should_update_history) | 99 if (!params.should_update_history) |
98 return; | 100 return; |
99 | 101 |
100 // Most of the time, the displayURL matches the loaded URL, but for about: | 102 // Most of the time, the displayURL matches the loaded URL, but for about: |
101 // URLs, we use a data: URL as the real value. We actually want to save the | 103 // URLs, we use a data: URL as the real value. We actually want to save the |
102 // about: URL to the history db and keep the data: URL hidden. This is what | 104 // about: URL to the history db and keep the data: URL hidden. This is what |
103 // the WebContents' URL getter does. | 105 // the WebContents' URL getter does. |
104 scoped_refptr<history::HistoryAddPageArgs> add_page_args( | 106 const history::HistoryAddPageArgs& add_page_args = |
105 CreateHistoryAddPageArgs(web_contents()->GetURL(), details, params)); | 107 CreateHistoryAddPageArgs(web_contents()->GetURL(), details, params); |
106 if (!web_contents()->GetDelegate() || | 108 if (!web_contents()->GetDelegate() || |
107 !web_contents()->GetDelegate()->ShouldAddNavigationToHistory( | 109 !web_contents()->GetDelegate()->ShouldAddNavigationToHistory( |
108 *add_page_args, details.type)) | 110 add_page_args, details.type)) |
109 return; | 111 return; |
110 | 112 |
111 UpdateHistoryForNavigation(add_page_args); | 113 UpdateHistoryForNavigation(add_page_args); |
112 } | 114 } |
113 | 115 |
114 void HistoryTabHelper::Observe(int type, | 116 void HistoryTabHelper::Observe(int type, |
115 const content::NotificationSource& source, | 117 const content::NotificationSource& source, |
116 const content::NotificationDetails& details) { | 118 const content::NotificationDetails& details) { |
117 DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED); | 119 DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED); |
118 std::pair<content::NavigationEntry*, bool>* title = | 120 std::pair<content::NavigationEntry*, bool>* title = |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 HistoryService* hs = | 187 HistoryService* hs = |
186 HistoryServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); | 188 HistoryServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); |
187 if (hs) { | 189 if (hs) { |
188 NavigationEntry* entry = tab->GetController().GetLastCommittedEntry(); | 190 NavigationEntry* entry = tab->GetController().GetLastCommittedEntry(); |
189 if (entry) { | 191 if (entry) { |
190 hs->UpdateWithPageEndTime(tab, entry->GetPageID(), tab->GetURL(), | 192 hs->UpdateWithPageEndTime(tab, entry->GetPageID(), tab->GetURL(), |
191 base::Time::Now()); | 193 base::Time::Now()); |
192 } | 194 } |
193 } | 195 } |
194 } | 196 } |
OLD | NEW |