| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 203 // highly. Note this means we're including clicks on not only most visited | 203 // highly. Note this means we're including clicks on not only most visited |
| 204 // thumbnails, but also clicks on recently bookmarked. | 204 // thumbnails, but also clicks on recently bookmarked. |
| 205 link_transition_type_ = PageTransition::AUTO_BOOKMARK; | 205 link_transition_type_ = PageTransition::AUTO_BOOKMARK; |
| 206 | 206 |
| 207 if (NewTabUI::FirstRunDisabled()) | |
| 208 NewTabHTMLSource::set_first_run(false); | |
| 209 | |
| 210 static bool first_view = true; | |
| 211 if (first_view) { | |
| 212 first_view = false; | |
| 213 } | |
| 214 | |
| 215 if (!GetProfile()->IsOffTheRecord()) { | 207 if (!GetProfile()->IsOffTheRecord()) { |
| 216 PrefService* pref_service = GetProfile()->GetPrefs(); | 208 PrefService* pref_service = GetProfile()->GetPrefs(); |
| 217 if (!NewTabSyncSetupHandler::ShouldShowSyncPromo()) | 209 if (!NewTabSyncSetupHandler::ShouldShowSyncPromo()) |
| 218 AddMessageHandler((new NTPLoginHandler())->Attach(this)); | 210 AddMessageHandler((new NTPLoginHandler())->Attach(this)); |
| 219 AddMessageHandler((new ShownSectionsHandler(pref_service))->Attach(this)); | 211 AddMessageHandler((new ShownSectionsHandler(pref_service))->Attach(this)); |
| 220 AddMessageHandler((new browser_sync::ForeignSessionHandler())-> | 212 AddMessageHandler((new browser_sync::ForeignSessionHandler())-> |
| 221 Attach(this)); | 213 Attach(this)); |
| 222 AddMessageHandler((new MostVisitedHandler())->Attach(this)); | 214 AddMessageHandler((new MostVisitedHandler())->Attach(this)); |
| 223 AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this)); | 215 AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this)); |
| 224 AddMessageHandler((new MetricsHandler())->Attach(this)); | 216 AddMessageHandler((new MetricsHandler())->Attach(this)); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 } | 362 } |
| 371 | 363 |
| 372 // static | 364 // static |
| 373 void NewTabUI::MigrateUserPrefs(PrefService* prefs, int old_pref_version, | 365 void NewTabUI::MigrateUserPrefs(PrefService* prefs, int old_pref_version, |
| 374 int new_pref_version) { | 366 int new_pref_version) { |
| 375 ShownSectionsHandler::MigrateUserPrefs(prefs, old_pref_version, | 367 ShownSectionsHandler::MigrateUserPrefs(prefs, old_pref_version, |
| 376 current_pref_version()); | 368 current_pref_version()); |
| 377 } | 369 } |
| 378 | 370 |
| 379 // static | 371 // static |
| 380 bool NewTabUI::FirstRunDisabled() { | |
| 381 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 382 return command_line->HasSwitch(switches::kDisableNewTabFirstRun); | |
| 383 } | |
| 384 | |
| 385 // static | |
| 386 void NewTabUI::SetURLTitleAndDirection(DictionaryValue* dictionary, | 372 void NewTabUI::SetURLTitleAndDirection(DictionaryValue* dictionary, |
| 387 const string16& title, | 373 const string16& title, |
| 388 const GURL& gurl) { | 374 const GURL& gurl) { |
| 389 dictionary->SetString("url", gurl.spec()); | 375 dictionary->SetString("url", gurl.spec()); |
| 390 | 376 |
| 391 bool using_url_as_the_title = false; | 377 bool using_url_as_the_title = false; |
| 392 string16 title_to_set(title); | 378 string16 title_to_set(title); |
| 393 if (title_to_set.empty()) { | 379 if (title_to_set.empty()) { |
| 394 using_url_as_the_title = true; | 380 using_url_as_the_title = true; |
| 395 title_to_set = UTF8ToUTF16(gurl.spec()); | 381 title_to_set = UTF8ToUTF16(gurl.spec()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 } | 414 } |
| 429 } | 415 } |
| 430 } | 416 } |
| 431 dictionary->SetString("title", title_to_set); | 417 dictionary->SetString("title", title_to_set); |
| 432 dictionary->SetString("direction", direction); | 418 dictionary->SetString("direction", direction); |
| 433 } | 419 } |
| 434 | 420 |
| 435 /////////////////////////////////////////////////////////////////////////////// | 421 /////////////////////////////////////////////////////////////////////////////// |
| 436 // NewTabHTMLSource | 422 // NewTabHTMLSource |
| 437 | 423 |
| 438 bool NewTabUI::NewTabHTMLSource::first_run_ = true; | |
| 439 | |
| 440 NewTabUI::NewTabHTMLSource::NewTabHTMLSource(Profile* profile) | 424 NewTabUI::NewTabHTMLSource::NewTabHTMLSource(Profile* profile) |
| 441 : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()), | 425 : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()), |
| 442 profile_(profile) { | 426 profile_(profile) { |
| 443 } | 427 } |
| 444 | 428 |
| 445 void NewTabUI::NewTabHTMLSource::StartDataRequest(const std::string& path, | 429 void NewTabUI::NewTabHTMLSource::StartDataRequest(const std::string& path, |
| 446 bool is_incognito, | 430 bool is_incognito, |
| 447 int request_id) { | 431 int request_id) { |
| 448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 432 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 449 | 433 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 463 SendResponse(request_id, html_bytes); | 447 SendResponse(request_id, html_bytes); |
| 464 } | 448 } |
| 465 | 449 |
| 466 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { | 450 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { |
| 467 return "text/html"; | 451 return "text/html"; |
| 468 } | 452 } |
| 469 | 453 |
| 470 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { | 454 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { |
| 471 return false; | 455 return false; |
| 472 } | 456 } |
| OLD | NEW |