| 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 (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4) && | 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 (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) { | 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 direction = kRTLHtmlTextDirection; | 411 direction = kRTLHtmlTextDirection; |
| 412 } else { | 412 } else { |
| 413 base::i18n::WrapStringWithLTRFormatting(&title_to_set); | 413 base::i18n::WrapStringWithLTRFormatting(&title_to_set); |
| 414 } | 414 } |
| 415 } | 415 } |
| 416 } | 416 } |
| 417 dictionary->SetString("title", title_to_set); | 417 dictionary->SetString("title", title_to_set); |
| 418 dictionary->SetString("direction", direction); | 418 dictionary->SetString("direction", direction); |
| 419 } | 419 } |
| 420 | 420 |
| 421 // static |
| 422 bool NewTabUI::Ntp4Enabled() { |
| 423 #if defined(TOUCH_UI) |
| 424 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage); |
| 425 #else |
| 426 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage); |
| 427 #endif |
| 428 } |
| 429 |
| 421 /////////////////////////////////////////////////////////////////////////////// | 430 /////////////////////////////////////////////////////////////////////////////// |
| 422 // NewTabHTMLSource | 431 // NewTabHTMLSource |
| 423 | 432 |
| 424 NewTabUI::NewTabHTMLSource::NewTabHTMLSource(Profile* profile) | 433 NewTabUI::NewTabHTMLSource::NewTabHTMLSource(Profile* profile) |
| 425 : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()), | 434 : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()), |
| 426 profile_(profile) { | 435 profile_(profile) { |
| 427 } | 436 } |
| 428 | 437 |
| 429 void NewTabUI::NewTabHTMLSource::StartDataRequest(const std::string& path, | 438 void NewTabUI::NewTabHTMLSource::StartDataRequest(const std::string& path, |
| 430 bool is_incognito, | 439 bool is_incognito, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 447 SendResponse(request_id, html_bytes); | 456 SendResponse(request_id, html_bytes); |
| 448 } | 457 } |
| 449 | 458 |
| 450 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { | 459 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { |
| 451 return "text/html"; | 460 return "text/html"; |
| 452 } | 461 } |
| 453 | 462 |
| 454 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { | 463 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { |
| 455 return false; | 464 return false; |
| 456 } | 465 } |
| OLD | NEW |