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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 7 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } // namespace | 182 } // namespace |
183 | 183 |
184 /////////////////////////////////////////////////////////////////////////////// | 184 /////////////////////////////////////////////////////////////////////////////// |
185 // NewTabUI | 185 // NewTabUI |
186 | 186 |
187 NewTabUI::NewTabUI(TabContents* contents) | 187 NewTabUI::NewTabUI(TabContents* contents) |
188 : ChromeWebUI(contents) { | 188 : ChromeWebUI(contents) { |
189 // Override some options on the Web UI. | 189 // Override some options on the Web UI. |
190 hide_favicon_ = true; | 190 hide_favicon_ = true; |
191 | 191 |
192 if (!Ntp4Enabled() && | 192 if (!NTP4Enabled() && |
193 GetProfile()->GetPrefs()->GetBoolean(prefs::kEnableBookmarkBar) && | 193 GetProfile()->GetPrefs()->GetBoolean(prefs::kEnableBookmarkBar) && |
194 browser_defaults::bookmarks_enabled) { | 194 browser_defaults::bookmarks_enabled) { |
195 set_force_bookmark_bar_visible(true); | 195 set_force_bookmark_bar_visible(true); |
196 } | 196 } |
197 | 197 |
198 focus_location_bar_by_default_ = true; | 198 focus_location_bar_by_default_ = true; |
199 should_hide_url_ = true; | 199 should_hide_url_ = true; |
200 overridden_title_ = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); | 200 overridden_title_ = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
201 | 201 |
202 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more | 202 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more |
(...skipping 13 matching lines...) Expand all Loading... |
216 AddMessageHandler((new MetricsHandler())->Attach(this)); | 216 AddMessageHandler((new MetricsHandler())->Attach(this)); |
217 if (GetProfile()->IsSyncAccessible()) | 217 if (GetProfile()->IsSyncAccessible()) |
218 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); | 218 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); |
219 ExtensionService* service = GetProfile()->GetExtensionService(); | 219 ExtensionService* service = GetProfile()->GetExtensionService(); |
220 // We might not have an ExtensionService (on ChromeOS when not logged in | 220 // We might not have an ExtensionService (on ChromeOS when not logged in |
221 // for example). | 221 // for example). |
222 if (service) | 222 if (service) |
223 AddMessageHandler((new AppLauncherHandler(service))->Attach(this)); | 223 AddMessageHandler((new AppLauncherHandler(service))->Attach(this)); |
224 | 224 |
225 AddMessageHandler((new NewTabPageHandler())->Attach(this)); | 225 AddMessageHandler((new NewTabPageHandler())->Attach(this)); |
226 if (Ntp4Enabled()) { | 226 if (NTP4Enabled()) { |
227 AddMessageHandler((new BookmarksHandler())->Attach(this)); | 227 AddMessageHandler((new BookmarksHandler())->Attach(this)); |
228 AddMessageHandler((new FaviconWebUIHandler())->Attach(this)); | 228 AddMessageHandler((new FaviconWebUIHandler())->Attach(this)); |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 // Add the sync setup handler for the sync promo UI. | 232 // Add the sync setup handler for the sync promo UI. |
233 scoped_ptr<SyncSetupHandler> handler(new NewTabSyncSetupHandler()); | 233 scoped_ptr<SyncSetupHandler> handler(new NewTabSyncSetupHandler()); |
234 AddMessageHandler(handler.release()->Attach(this)); | 234 AddMessageHandler(handler.release()->Attach(this)); |
235 | 235 |
236 // Initializing the CSS and HTML can require some CPU, so do it after | 236 // Initializing the CSS and HTML can require some CPU, so do it after |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 // static | 339 // static |
340 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { | 340 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { |
341 prefs->RegisterIntegerPref(prefs::kNTPPrefVersion, | 341 prefs->RegisterIntegerPref(prefs::kNTPPrefVersion, |
342 0, | 342 0, |
343 PrefService::UNSYNCABLE_PREF); | 343 PrefService::UNSYNCABLE_PREF); |
344 | 344 |
345 NewTabPageHandler::RegisterUserPrefs(prefs); | 345 NewTabPageHandler::RegisterUserPrefs(prefs); |
346 AppLauncherHandler::RegisterUserPrefs(prefs); | 346 AppLauncherHandler::RegisterUserPrefs(prefs); |
347 MostVisitedHandler::RegisterUserPrefs(prefs); | 347 MostVisitedHandler::RegisterUserPrefs(prefs); |
348 ShownSectionsHandler::RegisterUserPrefs(prefs); | 348 ShownSectionsHandler::RegisterUserPrefs(prefs); |
| 349 if (NTP4Enabled()) |
| 350 BookmarksHandler::RegisterUserPrefs(prefs); |
349 | 351 |
350 UpdateUserPrefsVersion(prefs); | 352 UpdateUserPrefsVersion(prefs); |
351 } | 353 } |
352 | 354 |
353 // static | 355 // static |
354 bool NewTabUI::UpdateUserPrefsVersion(PrefService* prefs) { | 356 bool NewTabUI::UpdateUserPrefsVersion(PrefService* prefs) { |
355 const int old_pref_version = prefs->GetInteger(prefs::kNTPPrefVersion); | 357 const int old_pref_version = prefs->GetInteger(prefs::kNTPPrefVersion); |
356 if (old_pref_version != current_pref_version()) { | 358 if (old_pref_version != current_pref_version()) { |
357 MigrateUserPrefs(prefs, old_pref_version, current_pref_version()); | 359 MigrateUserPrefs(prefs, old_pref_version, current_pref_version()); |
358 prefs->SetInteger(prefs::kNTPPrefVersion, current_pref_version()); | 360 prefs->SetInteger(prefs::kNTPPrefVersion, current_pref_version()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 } else { | 414 } else { |
413 base::i18n::WrapStringWithLTRFormatting(&title_to_set); | 415 base::i18n::WrapStringWithLTRFormatting(&title_to_set); |
414 } | 416 } |
415 } | 417 } |
416 } | 418 } |
417 dictionary->SetString("title", title_to_set); | 419 dictionary->SetString("title", title_to_set); |
418 dictionary->SetString("direction", direction); | 420 dictionary->SetString("direction", direction); |
419 } | 421 } |
420 | 422 |
421 // static | 423 // static |
422 bool NewTabUI::Ntp4Enabled() { | 424 bool NewTabUI::NTP4Enabled() { |
423 #if defined(TOUCH_UI) | 425 #if defined(TOUCH_UI) |
424 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage); | 426 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage); |
425 #else | 427 #else |
426 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage); | 428 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage); |
427 #endif | 429 #endif |
428 } | 430 } |
429 | 431 |
430 /////////////////////////////////////////////////////////////////////////////// | 432 /////////////////////////////////////////////////////////////////////////////// |
431 // NewTabHTMLSource | 433 // NewTabHTMLSource |
432 | 434 |
(...skipping 23 matching lines...) Expand all Loading... |
456 SendResponse(request_id, html_bytes); | 458 SendResponse(request_id, html_bytes); |
457 } | 459 } |
458 | 460 |
459 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { | 461 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { |
460 return "text/html"; | 462 return "text/html"; |
461 } | 463 } |
462 | 464 |
463 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { | 465 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { |
464 return false; | 466 return false; |
465 } | 467 } |
OLD | NEW |