OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "chrome/browser/dom_ui/new_tab_ui.h" | 7 #include "chrome/browser/dom_ui/new_tab_ui.h" |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 ScopedRunnableMethodFactory<PaintTimer> method_factory_; | 178 ScopedRunnableMethodFactory<PaintTimer> method_factory_; |
179 | 179 |
180 DISALLOW_COPY_AND_ASSIGN(PaintTimer); | 180 DISALLOW_COPY_AND_ASSIGN(PaintTimer); |
181 }; | 181 }; |
182 | 182 |
183 /////////////////////////////////////////////////////////////////////////////// | 183 /////////////////////////////////////////////////////////////////////////////// |
184 // NewTabHTMLSource | 184 // NewTabHTMLSource |
185 | 185 |
186 class NewTabHTMLSource : public ChromeURLDataManager::DataSource { | 186 class NewTabHTMLSource : public ChromeURLDataManager::DataSource { |
187 public: | 187 public: |
188 NewTabHTMLSource(); | 188 explicit NewTabHTMLSource(Profile* profile); |
189 | 189 |
190 // Called when the network layer has requested a resource underneath | 190 // Called when the network layer has requested a resource underneath |
191 // the path we registered. | 191 // the path we registered. |
192 virtual void StartDataRequest(const std::string& path, int request_id); | 192 virtual void StartDataRequest(const std::string& path, int request_id); |
193 | 193 |
194 virtual std::string GetMimeType(const std::string&) const { | 194 virtual std::string GetMimeType(const std::string&) const { |
195 return "text/html"; | 195 return "text/html"; |
196 } | 196 } |
197 | 197 |
198 // Setters and getters for first_view. | 198 // Setters and getters for first_view. |
199 static void set_first_view(bool first_view) { first_view_ = first_view; } | 199 static void set_first_view(bool first_view) { first_view_ = first_view; } |
200 static bool first_view() { return first_view_; } | 200 static bool first_view() { return first_view_; } |
201 | 201 |
202 private: | 202 private: |
203 // In case a file path to the new new tab page was provided this tries to load | 203 // In case a file path to the new new tab page was provided this tries to load |
204 // the file and returns the file content if successful. This returns an empty | 204 // the file and returns the file content if successful. This returns an empty |
205 // string in case of failure. | 205 // string in case of failure. |
206 static std::string GetNewNewTabFromCommandLine(); | 206 static std::string GetNewNewTabFromCommandLine(); |
207 | 207 |
208 // Whether this is the is the first viewing of the new tab page and | 208 // Whether this is the is the first viewing of the new tab page and |
209 // we think it is the user's startup page. | 209 // we think it is the user's startup page. |
210 static bool first_view_; | 210 static bool first_view_; |
211 | 211 |
| 212 // The user's profile. |
| 213 Profile* profile_; |
| 214 |
212 DISALLOW_COPY_AND_ASSIGN(NewTabHTMLSource); | 215 DISALLOW_COPY_AND_ASSIGN(NewTabHTMLSource); |
213 }; | 216 }; |
214 | 217 |
215 bool NewTabHTMLSource::first_view_ = true; | 218 bool NewTabHTMLSource::first_view_ = true; |
216 | 219 |
217 NewTabHTMLSource::NewTabHTMLSource() | 220 NewTabHTMLSource::NewTabHTMLSource(Profile* profile) |
218 : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()) { | 221 : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()), |
| 222 profile_(profile) { |
219 } | 223 } |
220 | 224 |
221 void NewTabHTMLSource::StartDataRequest(const std::string& path, | 225 void NewTabHTMLSource::StartDataRequest(const std::string& path, |
222 int request_id) { | 226 int request_id) { |
223 if (!path.empty()) { | 227 if (!path.empty()) { |
224 // A path under new-tab was requested; it's likely a bad relative | 228 // A path under new-tab was requested; it's likely a bad relative |
225 // URL from the new tab page, but in any case it's an error. | 229 // URL from the new tab page, but in any case it's an error. |
226 NOTREACHED(); | 230 NOTREACHED(); |
227 return; | 231 return; |
228 } | 232 } |
229 | 233 |
230 // Show the profile name in the title and most visited labels if the current | 234 // Show the profile name in the title and most visited labels if the current |
231 // profile is not the default. | 235 // profile is not the default. |
232 std::wstring title; | 236 std::wstring title; |
233 std::wstring most_visited; | 237 std::wstring most_visited; |
234 if (UserDataManager::Get()->is_current_profile_default()) { | 238 if (UserDataManager::Get()->is_current_profile_default()) { |
235 title = l10n_util::GetString(IDS_NEW_TAB_TITLE); | 239 title = l10n_util::GetString(IDS_NEW_TAB_TITLE); |
236 most_visited = l10n_util::GetString(IDS_NEW_TAB_MOST_VISITED); | 240 most_visited = l10n_util::GetString(IDS_NEW_TAB_MOST_VISITED); |
237 } else { | 241 } else { |
238 // Get the current profile name. | 242 // Get the current profile name. |
239 std::wstring profile_name = | 243 std::wstring profile_name = |
240 UserDataManager::Get()->current_profile_name(); | 244 UserDataManager::Get()->current_profile_name(); |
241 title = l10n_util::GetStringF(IDS_NEW_TAB_TITLE_WITH_PROFILE_NAME, | 245 title = l10n_util::GetStringF(IDS_NEW_TAB_TITLE_WITH_PROFILE_NAME, |
242 profile_name); | 246 profile_name); |
243 most_visited = l10n_util::GetStringF( | 247 most_visited = l10n_util::GetStringF( |
244 IDS_NEW_TAB_MOST_VISITED_WITH_PROFILE_NAME, | 248 IDS_NEW_TAB_MOST_VISITED_WITH_PROFILE_NAME, |
245 profile_name); | 249 profile_name); |
246 } | 250 } |
247 DictionaryValue localized_strings; | 251 DictionaryValue localized_strings; |
| 252 localized_strings.SetString(L"bookmarkbarattached", |
| 253 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ? |
| 254 "true" : "false"); |
248 localized_strings.SetString(L"title", title); | 255 localized_strings.SetString(L"title", title); |
249 localized_strings.SetString(L"mostvisited", most_visited); | 256 localized_strings.SetString(L"mostvisited", most_visited); |
250 localized_strings.SetString(L"searches", | 257 localized_strings.SetString(L"searches", |
251 l10n_util::GetString(IDS_NEW_TAB_SEARCHES)); | 258 l10n_util::GetString(IDS_NEW_TAB_SEARCHES)); |
252 localized_strings.SetString(L"bookmarks", | 259 localized_strings.SetString(L"bookmarks", |
253 l10n_util::GetString(IDS_NEW_TAB_BOOKMARKS)); | 260 l10n_util::GetString(IDS_NEW_TAB_BOOKMARKS)); |
254 localized_strings.SetString(L"recent", | 261 localized_strings.SetString(L"recent", |
255 l10n_util::GetString(IDS_NEW_TAB_RECENT)); | 262 l10n_util::GetString(IDS_NEW_TAB_RECENT)); |
256 localized_strings.SetString(L"showhistory", | 263 localized_strings.SetString(L"showhistory", |
257 l10n_util::GetString(IDS_NEW_TAB_HISTORY_SHOW)); | 264 l10n_util::GetString(IDS_NEW_TAB_HISTORY_SHOW)); |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 } | 1226 } |
1220 #endif | 1227 #endif |
1221 | 1228 |
1222 // In testing mode there may not be an I/O thread. | 1229 // In testing mode there may not be an I/O thread. |
1223 if (g_browser_process->io_thread()) { | 1230 if (g_browser_process->io_thread()) { |
1224 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 1231 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
1225 NewRunnableMethod(&chrome_url_data_manager, | 1232 NewRunnableMethod(&chrome_url_data_manager, |
1226 &ChromeURLDataManager::AddDataSource, | 1233 &ChromeURLDataManager::AddDataSource, |
1227 new DOMUIThemeSource(GetProfile()))); | 1234 new DOMUIThemeSource(GetProfile()))); |
1228 | 1235 |
1229 NewTabHTMLSource* html_source = new NewTabHTMLSource(); | 1236 NewTabHTMLSource* html_source = new NewTabHTMLSource(GetProfile()); |
1230 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 1237 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
1231 NewRunnableMethod(&chrome_url_data_manager, | 1238 NewRunnableMethod(&chrome_url_data_manager, |
1232 &ChromeURLDataManager::AddDataSource, | 1239 &ChromeURLDataManager::AddDataSource, |
1233 html_source)); | 1240 html_source)); |
1234 } | 1241 } |
1235 } | 1242 } |
1236 | 1243 |
1237 // Listen for theme installation. | 1244 // Listen for theme installation. |
1238 registrar_.Add(this, NotificationType::THEME_INSTALLED, | 1245 registrar_.Add(this, NotificationType::THEME_INSTALLED, |
1239 NotificationService::AllSources()); | 1246 NotificationService::AllSources()); |
| 1247 // Listen for bookmark bar visibility changes. |
| 1248 registrar_.Add(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
| 1249 NotificationService::AllSources()); |
1240 } | 1250 } |
1241 | 1251 |
1242 NewTabUI::~NewTabUI() { | 1252 NewTabUI::~NewTabUI() { |
1243 } | 1253 } |
1244 | 1254 |
1245 void NewTabUI::Observe(NotificationType type, | 1255 void NewTabUI::Observe(NotificationType type, |
1246 const NotificationSource& source, | 1256 const NotificationSource& source, |
1247 const NotificationDetails& details) { | 1257 const NotificationDetails& details) { |
1248 if (NotificationType::THEME_INSTALLED == type) { | 1258 if (NotificationType::THEME_INSTALLED == type) { |
1249 CallJavascriptFunction(L"themeChanged"); | 1259 CallJavascriptFunction(L"themeChanged"); |
| 1260 } else if (NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED) { |
| 1261 if (GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)) |
| 1262 CallJavascriptFunction(L"bookmarkBarAttached"); |
| 1263 else |
| 1264 CallJavascriptFunction(L"bookmarkBarDetached"); |
1250 } | 1265 } |
1251 } | 1266 } |
1252 | 1267 |
1253 | 1268 |
1254 // static | 1269 // static |
1255 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { | 1270 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { |
1256 MostVisitedHandler::RegisterUserPrefs(prefs); | 1271 MostVisitedHandler::RegisterUserPrefs(prefs); |
1257 } | 1272 } |
1258 | 1273 |
1259 // static | 1274 // static |
1260 bool NewTabUI::EnableNewNewTabPage() { | 1275 bool NewTabUI::EnableNewNewTabPage() { |
1261 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1276 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
1262 return command_line->HasSwitch(switches::kNewNewTabPage); | 1277 return command_line->HasSwitch(switches::kNewNewTabPage); |
1263 } | 1278 } |
OLD | NEW |