| 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/animation.h" | 9 #include "app/animation.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 virtual void StartDataRequest(const std::string& path, int request_id); | 195 virtual void StartDataRequest(const std::string& path, int request_id); |
| 196 | 196 |
| 197 virtual std::string GetMimeType(const std::string&) const { | 197 virtual std::string GetMimeType(const std::string&) const { |
| 198 return "text/html"; | 198 return "text/html"; |
| 199 } | 199 } |
| 200 | 200 |
| 201 // Setters and getters for first_view. | 201 // Setters and getters for first_view. |
| 202 static void set_first_view(bool first_view) { first_view_ = first_view; } | 202 static void set_first_view(bool first_view) { first_view_ = first_view; } |
| 203 static bool first_view() { return first_view_; } | 203 static bool first_view() { return first_view_; } |
| 204 | 204 |
| 205 // Setters and getters for first_run. |
| 206 static void set_first_run(bool first_run) { first_run_ = first_run; } |
| 207 static bool first_run() { return first_run_; } |
| 208 |
| 205 private: | 209 private: |
| 206 // In case a file path to the new tab page was provided this tries to load | 210 // In case a file path to the new tab page was provided this tries to load |
| 207 // the file and returns the file content if successful. This returns an empty | 211 // the file and returns the file content if successful. This returns an empty |
| 208 // string in case of failure. | 212 // string in case of failure. |
| 209 static std::string GetCustomNewTabPageFromCommandLine(); | 213 static std::string GetCustomNewTabPageFromCommandLine(); |
| 210 | 214 |
| 211 // Whether this is the is the first viewing of the new tab page and | 215 // Whether this is the first viewing of the new tab page and |
| 212 // we think it is the user's startup page. | 216 // we think it is the user's startup page. |
| 213 static bool first_view_; | 217 static bool first_view_; |
| 214 | 218 |
| 219 // Whether this is the first run. |
| 220 static bool first_run_; |
| 221 |
| 215 // The user's profile. | 222 // The user's profile. |
| 216 Profile* profile_; | 223 Profile* profile_; |
| 217 | 224 |
| 218 DISALLOW_COPY_AND_ASSIGN(NewTabHTMLSource); | 225 DISALLOW_COPY_AND_ASSIGN(NewTabHTMLSource); |
| 219 }; | 226 }; |
| 220 | 227 |
| 221 bool NewTabHTMLSource::first_view_ = true; | 228 bool NewTabHTMLSource::first_view_ = true; |
| 222 | 229 |
| 230 bool NewTabHTMLSource::first_run_ = true; |
| 231 |
| 223 NewTabHTMLSource::NewTabHTMLSource(Profile* profile) | 232 NewTabHTMLSource::NewTabHTMLSource(Profile* profile) |
| 224 : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()), | 233 : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()), |
| 225 profile_(profile) { | 234 profile_(profile) { |
| 226 } | 235 } |
| 227 | 236 |
| 228 void NewTabHTMLSource::StartDataRequest(const std::string& path, | 237 void NewTabHTMLSource::StartDataRequest(const std::string& path, |
| 229 int request_id) { | 238 int request_id) { |
| 230 if (!path.empty()) { | 239 if (!path.empty()) { |
| 231 // A path under new-tab was requested; it's likely a bad relative | 240 // A path under new-tab was requested; it's likely a bad relative |
| 232 // URL from the new tab page, but in any case it's an error. | 241 // URL from the new tab page, but in any case it's an error. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 localized_strings.SetString(L"pinthumbnailtooltip", | 343 localized_strings.SetString(L"pinthumbnailtooltip", |
| 335 l10n_util::GetString(IDS_NEW_TAB_PIN_THUMBNAIL_TOOLTIP)); | 344 l10n_util::GetString(IDS_NEW_TAB_PIN_THUMBNAIL_TOOLTIP)); |
| 336 localized_strings.SetString(L"unpinthumbnailtooltip", | 345 localized_strings.SetString(L"unpinthumbnailtooltip", |
| 337 l10n_util::GetString(IDS_NEW_TAB_UNPIN_THUMBNAIL_TOOLTIP)); | 346 l10n_util::GetString(IDS_NEW_TAB_UNPIN_THUMBNAIL_TOOLTIP)); |
| 338 localized_strings.SetString(L"showhidethumbnailtooltip", | 347 localized_strings.SetString(L"showhidethumbnailtooltip", |
| 339 l10n_util::GetString(IDS_NEW_TAB_SHOW_HIDE_THUMBNAIL_TOOLTIP)); | 348 l10n_util::GetString(IDS_NEW_TAB_SHOW_HIDE_THUMBNAIL_TOOLTIP)); |
| 340 localized_strings.SetString(L"showhidelisttooltip", | 349 localized_strings.SetString(L"showhidelisttooltip", |
| 341 l10n_util::GetString(IDS_NEW_TAB_SHOW_HIDE_LIST_TOOLTIP)); | 350 l10n_util::GetString(IDS_NEW_TAB_SHOW_HIDE_LIST_TOOLTIP)); |
| 342 localized_strings.SetString(L"pagedisplaytooltip", | 351 localized_strings.SetString(L"pagedisplaytooltip", |
| 343 l10n_util::GetString(IDS_NEW_TAB_PAGE_DISPLAY_TOOLTIP)); | 352 l10n_util::GetString(IDS_NEW_TAB_PAGE_DISPLAY_TOOLTIP)); |
| 353 localized_strings.SetString(L"firstrunnotification", |
| 354 l10n_util::GetString(IDS_NEW_TAB_FIRST_RUN_NOTIFICATION)); |
| 355 localized_strings.SetString(L"closefirstrunnotification", |
| 356 l10n_util::GetString(IDS_NEW_TAB_CLOSE_FIRST_RUN_NOTIFICATION)); |
| 344 | 357 |
| 345 SetFontAndTextDirection(&localized_strings); | 358 SetFontAndTextDirection(&localized_strings); |
| 346 | 359 |
| 347 // Let the tab know whether it's the first tab being viewed. | 360 // Let the tab know whether it's the first tab being viewed. |
| 348 localized_strings.SetString(L"firstview", | 361 localized_strings.SetString(L"firstview", |
| 349 first_view_ ? L"true" : std::wstring()); | 362 first_view_ ? L"true" : std::wstring()); |
| 350 first_view_ = false; | 363 first_view_ = false; |
| 351 | 364 |
| 352 // Control fade and resize animations. | 365 // Control fade and resize animations. |
| 353 std::wstring anim = | 366 std::wstring anim = |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 | 803 |
| 791 // Found a page. | 804 // Found a page. |
| 792 DictionaryValue* page_value = new DictionaryValue(); | 805 DictionaryValue* page_value = new DictionaryValue(); |
| 793 SetURLTitleAndDirection(page_value, title, url); | 806 SetURLTitleAndDirection(page_value, title, url); |
| 794 page_value->SetBoolean(L"pinned", pinned); | 807 page_value->SetBoolean(L"pinned", pinned); |
| 795 pages_value.Append(page_value); | 808 pages_value.Append(page_value); |
| 796 output_index++; | 809 output_index++; |
| 797 most_visited_urls_.push_back(url); | 810 most_visited_urls_.push_back(url); |
| 798 } | 811 } |
| 799 | 812 |
| 800 dom_ui_->CallJavascriptFunction(L"mostVisitedPages", pages_value); | 813 // If we found no pages we treat this as the first run. |
| 814 FundamentalValue first_run(NewTabHTMLSource::first_run() && |
| 815 pages_value.GetSize() == 0); |
| 816 // but first_run should only be true once. |
| 817 NewTabHTMLSource::set_first_run(false); |
| 818 |
| 819 dom_ui_->CallJavascriptFunction(L"mostVisitedPages", pages_value, first_run); |
| 801 } | 820 } |
| 802 | 821 |
| 803 void MostVisitedHandler::Observe(NotificationType type, | 822 void MostVisitedHandler::Observe(NotificationType type, |
| 804 const NotificationSource& source, | 823 const NotificationSource& source, |
| 805 const NotificationDetails& details) { | 824 const NotificationDetails& details) { |
| 806 if (type != NotificationType::HISTORY_URLS_DELETED) { | 825 if (type != NotificationType::HISTORY_URLS_DELETED) { |
| 807 NOTREACHED(); | 826 NOTREACHED(); |
| 808 return; | 827 return; |
| 809 } | 828 } |
| 810 | 829 |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1504 bool NewTabUI::UseOldNewTabPage() { | 1523 bool NewTabUI::UseOldNewTabPage() { |
| 1505 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1524 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 1506 return command_line->HasSwitch(switches::kOldNewTabPage); | 1525 return command_line->HasSwitch(switches::kOldNewTabPage); |
| 1507 } | 1526 } |
| 1508 | 1527 |
| 1509 // static | 1528 // static |
| 1510 bool NewTabUI::WebResourcesDisabled() { | 1529 bool NewTabUI::WebResourcesDisabled() { |
| 1511 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1530 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 1512 return command_line->HasSwitch(switches::kDisableWebResources); | 1531 return command_line->HasSwitch(switches::kDisableWebResources); |
| 1513 } | 1532 } |
| OLD | NEW |