OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/history/history.h" | 7 #include "chrome/browser/history/history.h" |
8 #include "chrome/browser/history/top_sites.h" | 8 #include "chrome/browser/history/top_sites.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
11 #include "content/browser/tab_contents/navigation_details.h" | 11 #include "content/browser/tab_contents/navigation_details.h" |
12 #include "content/browser/tab_contents/navigation_entry.h" | 12 #include "content/browser/tab_contents/navigation_entry.h" |
13 #include "content/browser/tab_contents/tab_contents.h" | 13 #include "content/browser/tab_contents/tab_contents.h" |
14 #include "content/browser/tab_contents/tab_contents_delegate.h" | 14 #include "content/browser/tab_contents/tab_contents_delegate.h" |
15 #include "content/browser/tab_contents/title_updated_details.h" | 15 #include "content/browser/tab_contents/title_updated_details.h" |
16 #include "content/common/view_messages.h" | |
17 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
18 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
19 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 19 #include "content/public/browser/notification_details.h" |
| 20 #include "content/public/common/frame_navigate_params.h" |
20 | 21 |
21 HistoryTabHelper::HistoryTabHelper(TabContents* tab_contents) | 22 HistoryTabHelper::HistoryTabHelper(TabContents* tab_contents) |
22 : TabContentsObserver(tab_contents), | 23 : TabContentsObserver(tab_contents), |
23 received_page_title_(false) { | 24 received_page_title_(false) { |
24 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED, | 25 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED, |
25 content::Source<TabContents>(tab_contents)); | 26 content::Source<TabContents>(tab_contents)); |
26 } | 27 } |
27 | 28 |
28 HistoryTabHelper::~HistoryTabHelper() { | 29 HistoryTabHelper::~HistoryTabHelper() { |
29 } | 30 } |
30 | 31 |
31 void HistoryTabHelper::UpdateHistoryForNavigation( | 32 void HistoryTabHelper::UpdateHistoryForNavigation( |
32 scoped_refptr<history::HistoryAddPageArgs> add_page_args) { | 33 scoped_refptr<history::HistoryAddPageArgs> add_page_args) { |
33 HistoryService* hs = GetHistoryService(); | 34 HistoryService* hs = GetHistoryService(); |
34 if (hs) | 35 if (hs) |
35 GetHistoryService()->AddPage(*add_page_args); | 36 GetHistoryService()->AddPage(*add_page_args); |
36 } | 37 } |
37 | 38 |
38 void HistoryTabHelper::UpdateHistoryPageTitle(const NavigationEntry& entry) { | 39 void HistoryTabHelper::UpdateHistoryPageTitle(const NavigationEntry& entry) { |
39 HistoryService* hs = GetHistoryService(); | 40 HistoryService* hs = GetHistoryService(); |
40 if (hs) | 41 if (hs) |
41 hs->SetPageTitle(entry.virtual_url(), entry.GetTitleForDisplay("")); | 42 hs->SetPageTitle(entry.virtual_url(), entry.GetTitleForDisplay("")); |
42 } | 43 } |
43 | 44 |
44 scoped_refptr<history::HistoryAddPageArgs> | 45 scoped_refptr<history::HistoryAddPageArgs> |
45 HistoryTabHelper::CreateHistoryAddPageArgs( | 46 HistoryTabHelper::CreateHistoryAddPageArgs( |
46 const GURL& virtual_url, | 47 const GURL& virtual_url, |
47 const content::LoadCommittedDetails& details, | 48 const content::LoadCommittedDetails& details, |
48 const ViewHostMsg_FrameNavigate_Params& params) { | 49 const content::FrameNavigateParams& params) { |
49 scoped_refptr<history::HistoryAddPageArgs> add_page_args( | 50 scoped_refptr<history::HistoryAddPageArgs> add_page_args( |
50 new history::HistoryAddPageArgs( | 51 new history::HistoryAddPageArgs( |
51 params.url, base::Time::Now(), tab_contents(), params.page_id, | 52 params.url, base::Time::Now(), tab_contents(), params.page_id, |
52 params.referrer, params.redirects, params.transition, | 53 params.referrer, params.redirects, params.transition, |
53 history::SOURCE_BROWSED, details.did_replace_entry)); | 54 history::SOURCE_BROWSED, details.did_replace_entry)); |
54 if (content::PageTransitionIsMainFrame(params.transition) && | 55 if (content::PageTransitionIsMainFrame(params.transition) && |
55 virtual_url != params.url) { | 56 virtual_url != params.url) { |
56 // Hack on the "virtual" URL so that it will appear in history. For some | 57 // Hack on the "virtual" URL so that it will appear in history. For some |
57 // types of URLs, we will display a magic URL that is different from where | 58 // types of URLs, we will display a magic URL that is different from where |
58 // the page is actually navigated. We want the user to see in history what | 59 // the page is actually navigated. We want the user to see in history what |
(...skipping 13 matching lines...) Expand all Loading... |
72 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PageContents, OnPageContents) | 73 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PageContents, OnPageContents) |
73 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_Thumbnail, OnThumbnail) | 74 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_Thumbnail, OnThumbnail) |
74 IPC_MESSAGE_UNHANDLED(handled = false) | 75 IPC_MESSAGE_UNHANDLED(handled = false) |
75 IPC_END_MESSAGE_MAP() | 76 IPC_END_MESSAGE_MAP() |
76 | 77 |
77 return handled; | 78 return handled; |
78 } | 79 } |
79 | 80 |
80 void HistoryTabHelper::DidNavigateMainFrame( | 81 void HistoryTabHelper::DidNavigateMainFrame( |
81 const content::LoadCommittedDetails& details, | 82 const content::LoadCommittedDetails& details, |
82 const ViewHostMsg_FrameNavigate_Params& params) { | 83 const content::FrameNavigateParams& params) { |
83 // Allow the new page to set the title again. | 84 // Allow the new page to set the title again. |
84 received_page_title_ = false; | 85 received_page_title_ = false; |
85 } | 86 } |
86 | 87 |
87 void HistoryTabHelper::DidNavigateAnyFrame( | 88 void HistoryTabHelper::DidNavigateAnyFrame( |
88 const content::LoadCommittedDetails& details, | 89 const content::LoadCommittedDetails& details, |
89 const ViewHostMsg_FrameNavigate_Params& params) { | 90 const content::FrameNavigateParams& params) { |
90 // Update history. Note that this needs to happen after the entry is complete, | 91 // Update history. Note that this needs to happen after the entry is complete, |
91 // which WillNavigate[Main,Sub]Frame will do before this function is called. | 92 // which WillNavigate[Main,Sub]Frame will do before this function is called. |
92 if (!params.should_update_history) | 93 if (!params.should_update_history) |
93 return; | 94 return; |
94 | 95 |
95 // Most of the time, the displayURL matches the loaded URL, but for about: | 96 // Most of the time, the displayURL matches the loaded URL, but for about: |
96 // URLs, we use a data: URL as the real value. We actually want to save the | 97 // URLs, we use a data: URL as the real value. We actually want to save the |
97 // about: URL to the history db and keep the data: URL hidden. This is what | 98 // about: URL to the history db and keep the data: URL hidden. This is what |
98 // the TabContents' URL getter does. | 99 // the TabContents' URL getter does. |
99 scoped_refptr<history::HistoryAddPageArgs> add_page_args( | 100 scoped_refptr<history::HistoryAddPageArgs> add_page_args( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 161 } |
161 | 162 |
162 HistoryService* HistoryTabHelper::GetHistoryService() { | 163 HistoryService* HistoryTabHelper::GetHistoryService() { |
163 Profile* profile = | 164 Profile* profile = |
164 Profile::FromBrowserContext(tab_contents()->browser_context()); | 165 Profile::FromBrowserContext(tab_contents()->browser_context()); |
165 if (profile->IsOffTheRecord()) | 166 if (profile->IsOffTheRecord()) |
166 return NULL; | 167 return NULL; |
167 | 168 |
168 return profile->GetHistoryService(Profile::IMPLICIT_ACCESS); | 169 return profile->GetHistoryService(Profile::IMPLICIT_ACCESS); |
169 } | 170 } |
OLD | NEW |