OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ui/search/search_tab_helper.h" | 5 #include "chrome/browser/ui/search/search_tab_helper.h" |
6 | 6 |
7 #include "chrome/browser/search/search.h" | 7 #include "chrome/browser/search/search.h" |
8 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
10 #include "content/public/browser/navigation_entry.h" | 10 #include "content/public/browser/navigation_entry.h" |
11 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
12 #include "content/public/browser/notification_types.h" | 12 #include "content/public/browser/notification_types.h" |
| 13 #include "grit/generated_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" |
13 | 15 |
14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SearchTabHelper); | 16 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SearchTabHelper); |
15 | 17 |
16 namespace { | 18 namespace { |
17 | 19 |
18 bool IsNTP(const content::WebContents* contents) { | 20 bool IsNTP(const content::WebContents* contents) { |
19 // We can't use WebContents::GetURL() because that uses the active entry, | 21 // We can't use WebContents::GetURL() because that uses the active entry, |
20 // whereas we want the visible entry. | 22 // whereas we want the visible entry. |
21 const content::NavigationEntry* entry = | 23 const content::NavigationEntry* entry = |
22 contents->GetController().GetVisibleEntry(); | 24 contents->GetController().GetVisibleEntry(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 88 |
87 void SearchTabHelper::Observe( | 89 void SearchTabHelper::Observe( |
88 int type, | 90 int type, |
89 const content::NotificationSource& source, | 91 const content::NotificationSource& source, |
90 const content::NotificationDetails& details) { | 92 const content::NotificationDetails& details) { |
91 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); | 93 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); |
92 UpdateMode(); | 94 UpdateMode(); |
93 last_known_most_visited_items_.clear(); | 95 last_known_most_visited_items_.clear(); |
94 } | 96 } |
95 | 97 |
| 98 void SearchTabHelper::DidNavigateMainFrame( |
| 99 const content::LoadCommittedDetails& details, |
| 100 const content::FrameNavigateParams& params) { |
| 101 // Always set the title on the new tab page to be the one from our UI |
| 102 // resources. Normally, we set the title when we begin a NTP load, but it |
| 103 // can get reset in several places (like when you press Reload). This check |
| 104 // ensures that the title is properly set to the string defined by the Chrome |
| 105 // UI language (rather than the server language) in all cases. |
| 106 // |
| 107 // We only override the title when it's nonempty to allow the page to set the |
| 108 // title if it really wants. An empty title means to use the default. There's |
| 109 // also a race condition between this code and the page's SetTitle call which |
| 110 // this rule avoids. |
| 111 content::NavigationEntry* entry = |
| 112 web_contents_->GetController().GetActiveEntry(); |
| 113 if (entry && entry->GetTitle().empty() && |
| 114 (entry->GetVirtualURL() == GURL(chrome::kChromeUINewTabURL) || |
| 115 chrome::NavEntryIsInstantNTP(web_contents_, entry))) { |
| 116 entry->SetTitle(l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); |
| 117 } |
| 118 } |
| 119 |
96 bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) { | 120 bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) { |
97 bool handled = true; | 121 bool handled = true; |
98 IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message) | 122 IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message) |
99 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowBars, | 123 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowBars, |
100 OnSearchBoxShowBars) | 124 OnSearchBoxShowBars) |
101 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars, | 125 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars, |
102 OnSearchBoxHideBars) | 126 OnSearchBoxHideBars) |
103 IPC_MESSAGE_UNHANDLED(handled = false) | 127 IPC_MESSAGE_UNHANDLED(handled = false) |
104 IPC_END_MESSAGE_MAP() | 128 IPC_END_MESSAGE_MAP() |
105 return handled; | 129 return handled; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 if (web_contents()->IsActiveEntry(page_id)) | 161 if (web_contents()->IsActiveEntry(page_id)) |
138 model_.SetTopBarsVisible(true); | 162 model_.SetTopBarsVisible(true); |
139 } | 163 } |
140 | 164 |
141 void SearchTabHelper::OnSearchBoxHideBars(int page_id) { | 165 void SearchTabHelper::OnSearchBoxHideBars(int page_id) { |
142 if (web_contents()->IsActiveEntry(page_id)) { | 166 if (web_contents()->IsActiveEntry(page_id)) { |
143 model_.SetTopBarsVisible(false); | 167 model_.SetTopBarsVisible(false); |
144 Send(new ChromeViewMsg_SearchBoxBarsHidden(routing_id())); | 168 Send(new ChromeViewMsg_SearchBoxBarsHidden(routing_id())); |
145 } | 169 } |
146 } | 170 } |
OLD | NEW |