Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: chrome/browser/dom_ui/new_tab_ui.cc

Issue 159475: Merge 21608 - , INNTP: Adds 2 hard coded thumbnails.... (Closed) Base URL: svn://chrome-svn/chrome/branches/195/src/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/app/theme/theme_resources.grd ('k') | chrome/browser/resources/new_new_tab.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Modified: svn:mergeinfo
Merged /trunk/src/chrome/browser/dom_ui/new_tab_ui.cc:r21608
OLDNEW
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 <set>
10
9 #include "app/animation.h" 11 #include "app/animation.h"
10 #include "app/l10n_util.h" 12 #include "app/l10n_util.h"
11 #include "app/resource_bundle.h" 13 #include "app/resource_bundle.h"
12 #include "base/command_line.h" 14 #include "base/command_line.h"
13 #include "base/file_util.h" 15 #include "base/file_util.h"
14 #include "base/histogram.h" 16 #include "base/histogram.h"
15 #include "base/string_piece.h" 17 #include "base/string_piece.h"
16 #include "chrome/browser/bookmarks/bookmark_model.h" 18 #include "chrome/browser/bookmarks/bookmark_model.h"
17 #include "chrome/browser/bookmarks/bookmark_utils.h" 19 #include "chrome/browser/bookmarks/bookmark_utils.h"
18 #include "chrome/browser/browser.h" 20 #include "chrome/browser/browser.h"
(...skipping 26 matching lines...) Expand all
45 #include "chrome/personalization/personalization.h" 47 #include "chrome/personalization/personalization.h"
46 #endif 48 #endif
47 #include "grit/browser_resources.h" 49 #include "grit/browser_resources.h"
48 #include "grit/chromium_strings.h" 50 #include "grit/chromium_strings.h"
49 #include "grit/generated_resources.h" 51 #include "grit/generated_resources.h"
50 #include "grit/locale_settings.h" 52 #include "grit/locale_settings.h"
51 53
52 namespace { 54 namespace {
53 55
54 // The number of most visited pages we show. 56 // The number of most visited pages we show.
55 const size_t kMostVisitedPages = 9; 57 const size_t kMostVisitedPages = 8;
58
59 // The number of most visited pages we show on the old new tab page.
60 const size_t kOldMostVisitedPages = 9;
56 61
57 // The number of days of history we consider for most visited entries. 62 // The number of days of history we consider for most visited entries.
58 const int kMostVisitedScope = 90; 63 const int kMostVisitedScope = 90;
59 64
60 // The number of recent bookmarks we show. 65 // The number of recent bookmarks we show.
61 const int kRecentBookmarks = 9; 66 const int kRecentBookmarks = 9;
62 67
63 // The number of search URLs to show. 68 // The number of search URLs to show.
64 const int kSearchURLs = 3; 69 const int kSearchURLs = 3;
65 70
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 incognito_tab_html, &localized_strings); 472 incognito_tab_html, &localized_strings);
468 473
469 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); 474 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
470 html_bytes->data.resize(full_html.size()); 475 html_bytes->data.resize(full_html.size());
471 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); 476 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
472 477
473 SendResponse(request_id, html_bytes); 478 SendResponse(request_id, html_bytes);
474 } 479 }
475 480
476 /////////////////////////////////////////////////////////////////////////////// 481 ///////////////////////////////////////////////////////////////////////////////
482 // MostVisitedPage
483
484 // This struct is used when getting the prepopulated pages in case the user
485 // hasn't filled up his most visited pages.
486 struct MostVisitedPage {
487 std::wstring title;
488 GURL url;
489 GURL thumbnail_url;
490 GURL favicon_url;
491 };
492
493 ///////////////////////////////////////////////////////////////////////////////
477 // MostVisitedHandler 494 // MostVisitedHandler
478 495
479 // The handler for Javascript messages related to the "most visited" view. 496 // The handler for Javascript messages related to the "most visited" view.
480 class MostVisitedHandler : public DOMMessageHandler, 497 class MostVisitedHandler : public DOMMessageHandler,
481 public NotificationObserver { 498 public NotificationObserver {
482 public: 499 public:
483 MostVisitedHandler() : url_blacklist_(NULL), pinned_urls_(NULL) {} 500 MostVisitedHandler() : url_blacklist_(NULL), pinned_urls_(NULL) {}
484 virtual ~MostVisitedHandler() { } 501 virtual ~MostVisitedHandler() { }
485 502
486 // DOMMessageHandler override and implementation. 503 // DOMMessageHandler override and implementation.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 std::wstring GetDictionaryKeyForURL(const std::string& url); 546 std::wstring GetDictionaryKeyForURL(const std::string& url);
530 547
531 // Gets the |url| and |title| for a pinned URL at a given index. This returns 548 // Gets the |url| and |title| for a pinned URL at a given index. This returns
532 // true if found. 549 // true if found.
533 const bool GetPinnedURLAtIndex(const int index, std::string* url, 550 const bool GetPinnedURLAtIndex(const int index, std::string* url,
534 std::string* title); 551 std::string* title);
535 552
536 void AddPinnedURL(const GURL& url, const std::string& title, int index); 553 void AddPinnedURL(const GURL& url, const std::string& title, int index);
537 void RemovePinnedURL(const GURL& url); 554 void RemovePinnedURL(const GURL& url);
538 555
556 static std::vector<MostVisitedPage> GetPrePopulatedPages();
557
539 NotificationRegistrar registrar_; 558 NotificationRegistrar registrar_;
540 559
541 // Our consumer for the history service. 560 // Our consumer for the history service.
542 CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_; 561 CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_;
543 562
544 // The most visited URLs, in priority order. 563 // The most visited URLs, in priority order.
545 // Only used for matching up clicks on the page to which most visited entry 564 // Only used for matching up clicks on the page to which most visited entry
546 // was clicked on for metrics purposes. 565 // was clicked on for metrics purposes.
547 std::vector<GURL> most_visited_urls_; 566 std::vector<GURL> most_visited_urls_;
548 567
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 } 785 }
767 786
768 return false; 787 return false;
769 } 788 }
770 789
771 void MostVisitedHandler::OnSegmentUsageAvailable( 790 void MostVisitedHandler::OnSegmentUsageAvailable(
772 CancelableRequestProvider::Handle handle, 791 CancelableRequestProvider::Handle handle,
773 std::vector<PageUsageData*>* data) { 792 std::vector<PageUsageData*>* data) {
774 most_visited_urls_.clear(); 793 most_visited_urls_.clear();
775 ListValue pages_value; 794 ListValue pages_value;
795 std::set<GURL> seen_urls;
776 796
777 size_t data_index = 0; 797 size_t data_index = 0;
778 size_t output_index = 0; 798 size_t output_index = 0;
779 while (output_index < kMostVisitedPages && data_index < data->size()) { 799 const size_t pages_count = NewTabUI::UseOldNewTabPage() ?
800 kOldMostVisitedPages : kMostVisitedPages;
801 while (output_index < pages_count && data_index < data->size()) {
780 bool pinned = false; 802 bool pinned = false;
781 GURL url; 803 GURL url;
782 string16 title; 804 string16 title;
783 std::string pinned_url; 805 std::string pinned_url;
784 std::string pinned_title; 806 std::string pinned_title;
785 807
786 if (MostVisitedHandler::GetPinnedURLAtIndex(output_index, &pinned_url, 808 if (MostVisitedHandler::GetPinnedURLAtIndex(output_index, &pinned_url,
787 &pinned_title)) { 809 &pinned_title)) {
788 url = GURL(pinned_url); 810 url = GURL(pinned_url);
789 title = UTF8ToUTF16(pinned_title); 811 title = UTF8ToUTF16(pinned_title);
(...skipping 11 matching lines...) Expand all
801 title = page.GetTitle(); 823 title = page.GetTitle();
802 } 824 }
803 825
804 // Found a page. 826 // Found a page.
805 DictionaryValue* page_value = new DictionaryValue(); 827 DictionaryValue* page_value = new DictionaryValue();
806 SetURLTitleAndDirection(page_value, title, url); 828 SetURLTitleAndDirection(page_value, title, url);
807 page_value->SetBoolean(L"pinned", pinned); 829 page_value->SetBoolean(L"pinned", pinned);
808 pages_value.Append(page_value); 830 pages_value.Append(page_value);
809 output_index++; 831 output_index++;
810 most_visited_urls_.push_back(url); 832 most_visited_urls_.push_back(url);
833 seen_urls.insert(url);
811 } 834 }
812 835
813 // If we found no pages we treat this as the first run. 836 // If we found no pages we treat this as the first run.
814 FundamentalValue first_run(NewTabHTMLSource::first_run() && 837 FundamentalValue first_run(NewTabHTMLSource::first_run() &&
815 pages_value.GetSize() == 0); 838 pages_value.GetSize() == 0);
816 // but first_run should only be true once. 839 // but first_run should only be true once.
817 NewTabHTMLSource::set_first_run(false); 840 NewTabHTMLSource::set_first_run(false);
818 841
842 // If we have less than pages_count we add some predetermined pages.
843 if (pages_value.GetSize() < pages_count) {
844 static std::vector<MostVisitedPage> pages =
845 MostVisitedHandler::GetPrePopulatedPages();
846 for (std::vector<MostVisitedPage>::const_iterator it = pages.begin();
847 it != pages.end() && pages_value.GetSize() < pages_count;
848 ++it) {
849 MostVisitedPage page = *it;
850 std::wstring key = GetDictionaryKeyForURL(page.url.spec());
851 if (!pinned_urls_->HasKey(key) && !url_blacklist_->HasKey(key) &&
852 seen_urls.find(page.url) == seen_urls.end()) {
853 DictionaryValue* page_value = new DictionaryValue();
854 SetURLTitleAndDirection(page_value, WideToUTF16(page.title), page.url);
855 page_value->SetBoolean(L"pinned", false);
856 page_value->SetString(L"thumbnailUrl", page.thumbnail_url.spec());
857 page_value->SetString(L"faviconUrl", page.favicon_url.spec());
858 pages_value.Append(page_value);
859 most_visited_urls_.push_back(page.url);
860 seen_urls.insert(page.url);
861 }
862 }
863 }
864
819 dom_ui_->CallJavascriptFunction(L"mostVisitedPages", pages_value, first_run); 865 dom_ui_->CallJavascriptFunction(L"mostVisitedPages", pages_value, first_run);
820 } 866 }
821 867
868 // static
869 std::vector<MostVisitedPage> MostVisitedHandler::GetPrePopulatedPages() {
870 // TODO(arv): This needs to get the data from some configurable place.
871 // http://crbug.com/17630
872 std::vector<MostVisitedPage> pages;
873
874 MostVisitedPage welcome_page = {
875 l10n_util::GetString(IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE),
876 GURL(WideToUTF8(l10n_util::GetString(IDS_CHROME_WELCOME_URL))),
877 GURL("chrome://theme/newtab_chrome_welcome_page_thumbnail"),
878 GURL("chrome://theme/newtab_chrome_welcome_page_favicon")};
879 pages.push_back(welcome_page);
880
881 MostVisitedPage gallery_page = {
882 l10n_util::GetString(IDS_NEW_TAB_THEMES_GALLERY_PAGE_TITLE),
883 GURL(WideToUTF8(l10n_util::GetString(IDS_THEMES_GALLERY_URL))),
884 GURL("chrome://theme/newtab_themes_gallery_thumbnail"),
885 GURL("chrome://theme/newtab_themes_gallery_favicon")};
886 pages.push_back(gallery_page);
887
888 return pages;
889 }
890
822 void MostVisitedHandler::Observe(NotificationType type, 891 void MostVisitedHandler::Observe(NotificationType type,
823 const NotificationSource& source, 892 const NotificationSource& source,
824 const NotificationDetails& details) { 893 const NotificationDetails& details) {
825 if (type != NotificationType::HISTORY_URLS_DELETED) { 894 if (type != NotificationType::HISTORY_URLS_DELETED) {
826 NOTREACHED(); 895 NOTREACHED();
827 return; 896 return;
828 } 897 }
829 898
830 // Some URLs were deleted from history. Reload the most visited list. 899 // Some URLs were deleted from history. Reload the most visited list.
831 HandleGetMostVisited(NULL); 900 HandleGetMostVisited(NULL);
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 bool NewTabUI::UseOldNewTabPage() { 1592 bool NewTabUI::UseOldNewTabPage() {
1524 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 1593 const CommandLine* command_line = CommandLine::ForCurrentProcess();
1525 return command_line->HasSwitch(switches::kOldNewTabPage); 1594 return command_line->HasSwitch(switches::kOldNewTabPage);
1526 } 1595 }
1527 1596
1528 // static 1597 // static
1529 bool NewTabUI::WebResourcesDisabled() { 1598 bool NewTabUI::WebResourcesDisabled() {
1530 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 1599 const CommandLine* command_line = CommandLine::ForCurrentProcess();
1531 return command_line->HasSwitch(switches::kDisableWebResources); 1600 return command_line->HasSwitch(switches::kDisableWebResources);
1532 } 1601 }
OLDNEW
« no previous file with comments | « chrome/app/theme/theme_resources.grd ('k') | chrome/browser/resources/new_new_tab.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698