OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/dom_ui/most_visited_handler.h" | 5 #include "chrome/browser/dom_ui/most_visited_handler.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "chrome/browser/history/history.h" | 26 #include "chrome/browser/history/history.h" |
27 #include "chrome/browser/history/top_sites.h" | 27 #include "chrome/browser/history/top_sites.h" |
28 #include "chrome/browser/metrics/user_metrics.h" | 28 #include "chrome/browser/metrics/user_metrics.h" |
29 #include "chrome/browser/pref_service.h" | 29 #include "chrome/browser/pref_service.h" |
30 #include "chrome/browser/profile.h" | 30 #include "chrome/browser/profile.h" |
31 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/extensions/extension.h" | 32 #include "chrome/common/extensions/extension.h" |
33 #include "chrome/common/notification_type.h" | 33 #include "chrome/common/notification_type.h" |
34 #include "chrome/common/notification_source.h" | 34 #include "chrome/common/notification_source.h" |
35 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 36 #include "googleurl/src/gurl.h" |
36 #include "grit/chromium_strings.h" | 37 #include "grit/chromium_strings.h" |
37 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
38 #include "grit/locale_settings.h" | 39 #include "grit/locale_settings.h" |
39 | 40 |
40 namespace { | 41 namespace { |
41 | 42 |
42 // The number of most visited pages we show. | 43 // The number of most visited pages we show. |
43 const size_t kMostVisitedPages = 8; | 44 const size_t kMostVisitedPages = 8; |
44 | 45 |
45 // The number of days of history we consider for most visited entries. | 46 // The number of days of history we consider for most visited entries. |
46 const int kMostVisitedScope = 90; | 47 const int kMostVisitedScope = 90; |
47 | 48 |
48 // Adds the fields in the page to the dictionary. | 49 } // namespace |
49 void SetMostVisistedPage(DictionaryValue* dict, | |
50 const MostVisitedHandler::MostVisitedPage& page) { | |
51 NewTabUI::SetURLTitleAndDirection(dict, WideToUTF16(page.title), page.url); | |
52 if (!page.favicon_url.is_empty()) | |
53 dict->SetString(L"faviconUrl", page.favicon_url.spec()); | |
54 if (!page.thumbnail_url.is_empty()) | |
55 dict->SetString(L"thumbnailUrl", page.thumbnail_url.spec()); | |
56 } | |
57 | 50 |
58 } // namespace | 51 // This struct is used when getting the pre-populated pages in case the user |
| 52 // hasn't filled up his most visited pages. |
| 53 struct MostVisitedHandler::MostVisitedPage { |
| 54 std::wstring title; |
| 55 GURL url; |
| 56 GURL thumbnail_url; |
| 57 GURL favicon_url; |
| 58 }; |
59 | 59 |
60 MostVisitedHandler::MostVisitedHandler() | 60 MostVisitedHandler::MostVisitedHandler() |
61 : url_blacklist_(NULL), | 61 : url_blacklist_(NULL), |
62 pinned_urls_(NULL), | 62 pinned_urls_(NULL), |
63 got_first_most_visited_request_(false) { | 63 got_first_most_visited_request_(false) { |
64 } | 64 } |
65 | 65 |
66 DOMMessageHandler* MostVisitedHandler::Attach(DOMUI* dom_ui) { | 66 DOMMessageHandler* MostVisitedHandler::Attach(DOMUI* dom_ui) { |
67 url_blacklist_ = dom_ui->GetProfile()->GetPrefs()-> | 67 url_blacklist_ = dom_ui->GetProfile()->GetPrefs()-> |
68 GetMutableDictionary(prefs::kNTPMostVisitedURLsBlacklist); | 68 GetMutableDictionary(prefs::kNTPMostVisitedURLsBlacklist); |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 // If we found no pages we treat this as the first run. | 534 // If we found no pages we treat this as the first run. |
535 bool first_run = NewTabUI::NewTabHTMLSource::first_run() && | 535 bool first_run = NewTabUI::NewTabHTMLSource::first_run() && |
536 pages_value_->GetSize() == | 536 pages_value_->GetSize() == |
537 MostVisitedHandler::GetPrePopulatedPages().size(); | 537 MostVisitedHandler::GetPrePopulatedPages().size(); |
538 // but first_run should only be true once. | 538 // but first_run should only be true once. |
539 NewTabUI::NewTabHTMLSource::set_first_run(false); | 539 NewTabUI::NewTabHTMLSource::set_first_run(false); |
540 return first_run; | 540 return first_run; |
541 } | 541 } |
542 | 542 |
543 // static | 543 // static |
| 544 void MostVisitedHandler::SetMostVisistedPage( |
| 545 DictionaryValue* dict, |
| 546 const MostVisitedHandler::MostVisitedPage& page) { |
| 547 NewTabUI::SetURLTitleAndDirection(dict, WideToUTF16(page.title), page.url); |
| 548 if (!page.favicon_url.is_empty()) |
| 549 dict->SetString(L"faviconUrl", page.favicon_url.spec()); |
| 550 if (!page.thumbnail_url.is_empty()) |
| 551 dict->SetString(L"thumbnailUrl", page.thumbnail_url.spec()); |
| 552 } |
| 553 |
| 554 |
| 555 // static |
544 const std::vector<MostVisitedHandler::MostVisitedPage>& | 556 const std::vector<MostVisitedHandler::MostVisitedPage>& |
545 MostVisitedHandler::GetPrePopulatedPages() { | 557 MostVisitedHandler::GetPrePopulatedPages() { |
546 // TODO(arv): This needs to get the data from some configurable place. | 558 // TODO(arv): This needs to get the data from some configurable place. |
547 // http://crbug.com/17630 | 559 // http://crbug.com/17630 |
548 static std::vector<MostVisitedPage> pages; | 560 static std::vector<MostVisitedPage> pages; |
549 if (pages.empty()) { | 561 if (pages.empty()) { |
550 MostVisitedPage welcome_page = { | 562 MostVisitedPage welcome_page = { |
551 l10n_util::GetString(IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE), | 563 l10n_util::GetString(IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE), |
552 GURL(WideToUTF8(l10n_util::GetString(IDS_CHROME_WELCOME_URL))), | 564 GURL(WideToUTF8(l10n_util::GetString(IDS_CHROME_WELCOME_URL))), |
553 GURL("chrome://theme/IDR_NEWTAB_CHROME_WELCOME_PAGE_THUMBNAIL"), | 565 GURL("chrome://theme/IDR_NEWTAB_CHROME_WELCOME_PAGE_THUMBNAIL"), |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedPinnedURLs); | 631 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedPinnedURLs); |
620 } | 632 } |
621 | 633 |
622 bool MostVisitedHandler::HasApps() const { | 634 bool MostVisitedHandler::HasApps() const { |
623 ExtensionsService* service = dom_ui_->GetProfile()->GetExtensionsService(); | 635 ExtensionsService* service = dom_ui_->GetProfile()->GetExtensionsService(); |
624 if (!service) | 636 if (!service) |
625 return false; | 637 return false; |
626 | 638 |
627 return service->HasApps(); | 639 return service->HasApps(); |
628 } | 640 } |
OLD | NEW |