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

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

Issue 147226: Make the new new tab page the default new tab page.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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
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 "app/animation.h" 9 #include "app/animation.h"
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 private: 205 private:
206 // In case a file path to the new new tab page was provided this tries to load 206 // 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 207 // the file and returns the file content if successful. This returns an empty
208 // string in case of failure. 208 // string in case of failure.
209 static std::string GetNewNewTabFromCommandLine(); 209 static std::string GetNewTabPageFromCommandLine();
210 210
211 // Whether this is the is the first viewing of the new tab page and 211 // Whether this is the is the first viewing of the new tab page and
212 // we think it is the user's startup page. 212 // we think it is the user's startup page.
213 static bool first_view_; 213 static bool first_view_;
214 214
215 // The user's profile. 215 // The user's profile.
216 Profile* profile_; 216 Profile* profile_;
217 217
218 DISALLOW_COPY_AND_ASSIGN(NewTabHTMLSource); 218 DISALLOW_COPY_AND_ASSIGN(NewTabHTMLSource);
219 }; 219 };
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 342
343 // Control fade and resize animations. 343 // Control fade and resize animations.
344 std::wstring anim = 344 std::wstring anim =
345 Animation::ShouldRenderRichAnimation() ? L"true" : L"false"; 345 Animation::ShouldRenderRichAnimation() ? L"true" : L"false";
346 localized_strings.SetString(L"anim", anim); 346 localized_strings.SetString(L"anim", anim);
347 347
348 #ifdef CHROME_PERSONALIZATION 348 #ifdef CHROME_PERSONALIZATION
349 localized_strings.SetString(L"p13nsrc", Personalization::GetNewTabSource()); 349 localized_strings.SetString(L"p13nsrc", Personalization::GetNewTabSource());
350 #endif 350 #endif
351 351
352 // In case we have the new new tab page enabled we first try to read the file 352 // In case we have a custom new tab page enabled we first try to read the
353 // provided on the command line. If that fails we just get the resource from 353 // file provided on the command line. If that fails we just get the default
354 // the resource bundle. 354 // resource from the resource bundle.
355 StringPiece new_tab_html; 355 StringPiece new_tab_html;
356 std::string new_tab_html_str; 356 std::string new_tab_html_str = GetNewTabPageFromCommandLine();
357 if (NewTabUI::EnableNewNewTabPage()) {
358 new_tab_html_str = GetNewNewTabFromCommandLine();
359 357
360 if (!new_tab_html_str.empty()) { 358 if (!new_tab_html_str.empty()) {
361 new_tab_html = StringPiece(new_tab_html_str); 359 new_tab_html = StringPiece(new_tab_html_str);
362 } else { 360 }
363 // Use the new new tab page from the resource bundle. 361
364 new_tab_html = ResourceBundle::GetSharedInstance().GetRawDataResource( 362 // No custom new tab page or the file was empty.
365 IDR_NEW_NEW_TAB_HTML); 363 if (new_tab_html.empty()) {
366 }
367 } else {
368 // Use the default new tab page resource. 364 // Use the default new tab page resource.
369 new_tab_html = ResourceBundle::GetSharedInstance().GetRawDataResource( 365 new_tab_html = ResourceBundle::GetSharedInstance().GetRawDataResource(
370 IDR_NEW_TAB_HTML); 366 IDR_NEW_TAB_HTML);
371 } 367 }
372 368
373 const std::string full_html = jstemplate_builder::GetTemplateHtml( 369 const std::string full_html = jstemplate_builder::GetTemplateHtml(
374 new_tab_html, &localized_strings, "t" /* template root node id */); 370 new_tab_html, &localized_strings, "t" /* template root node id */);
375 371
376 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); 372 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
377 html_bytes->data.resize(full_html.size()); 373 html_bytes->data.resize(full_html.size());
378 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); 374 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
379 375
380 SendResponse(request_id, html_bytes); 376 SendResponse(request_id, html_bytes);
381 } 377 }
382 378
383 // static 379 // static
384 std::string NewTabHTMLSource::GetNewNewTabFromCommandLine() { 380 std::string NewTabHTMLSource::GetNewTabPageFromCommandLine() {
385 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 381 const CommandLine* command_line = CommandLine::ForCurrentProcess();
386 const std::wstring file_path_wstring = command_line->GetSwitchValue( 382 const std::wstring file_path_wstring = command_line->GetSwitchValue(
387 switches::kNewNewTabPage); 383 switches::kNewTabPage);
388 384
389 #if defined(OS_WIN) 385 #if defined(OS_WIN)
390 const FilePath::StringType file_path = file_path_wstring; 386 const FilePath::StringType file_path = file_path_wstring;
391 #else 387 #else
392 const FilePath::StringType file_path = WideToASCII(file_path_wstring); 388 const FilePath::StringType file_path = WideToASCII(file_path_wstring);
393 #endif 389 #endif
394 390
395 if (!file_path.empty()) { 391 if (!file_path.empty()) {
396 std::string file_contents; 392 std::string file_contents;
397 if (file_util::ReadFileToString(FilePath(file_path), &file_contents)) 393 if (file_util::ReadFileToString(FilePath(file_path), &file_contents))
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 return ASCIIToWide(MD5String(url)); 811 return ASCIIToWide(MD5String(url));
816 } 812 }
817 813
818 // static 814 // static
819 void MostVisitedHandler::RegisterUserPrefs(PrefService* prefs) { 815 void MostVisitedHandler::RegisterUserPrefs(PrefService* prefs) {
820 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedURLsBlacklist); 816 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedURLsBlacklist);
821 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedPinnedURLs); 817 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedPinnedURLs);
822 } 818 }
823 819
824 /////////////////////////////////////////////////////////////////////////////// 820 ///////////////////////////////////////////////////////////////////////////////
825 // TemplateURLHandler
826
827 // The handler for Javascript messages related to the "common searches" view.
828 class TemplateURLHandler : public DOMMessageHandler,
829 public TemplateURLModelObserver {
830 public:
831 explicit TemplateURLHandler(DOMUI* dom_ui);
832 virtual ~TemplateURLHandler();
833
834 // Callback for the "getMostSearched" message, sent when the page requests
835 // the list of available searches.
836 void HandleGetMostSearched(const Value* content);
837 // Callback for the "doSearch" message, sent when the user wants to
838 // run a search. Content of the message is an array containing
839 // [<the search keyword>, <the search term>].
840 void HandleDoSearch(const Value* content);
841
842 // TemplateURLModelObserver implementation.
843 virtual void OnTemplateURLModelChanged();
844
845 private:
846 DOMUI* dom_ui_;
847 TemplateURLModel* template_url_model_; // Owned by profile.
848
849 DISALLOW_COPY_AND_ASSIGN(TemplateURLHandler);
850 };
851
852 TemplateURLHandler::TemplateURLHandler(DOMUI* dom_ui)
853 : DOMMessageHandler(dom_ui),
854 dom_ui_(dom_ui),
855 template_url_model_(NULL) {
856 dom_ui->RegisterMessageCallback("getMostSearched",
857 NewCallback(this, &TemplateURLHandler::HandleGetMostSearched));
858 dom_ui->RegisterMessageCallback("doSearch",
859 NewCallback(this, &TemplateURLHandler::HandleDoSearch));
860 }
861
862 TemplateURLHandler::~TemplateURLHandler() {
863 if (template_url_model_)
864 template_url_model_->RemoveObserver(this);
865 }
866
867 void TemplateURLHandler::HandleGetMostSearched(const Value* content) {
868 // The page Javascript has requested the list of keyword searches.
869 // Start loading them from the template URL backend.
870 if (!template_url_model_) {
871 template_url_model_ = dom_ui_->GetProfile()->GetTemplateURLModel();
872 template_url_model_->AddObserver(this);
873 }
874 if (template_url_model_->loaded()) {
875 OnTemplateURLModelChanged();
876 } else {
877 template_url_model_->Load();
878 }
879 }
880
881 // A helper function for sorting TemplateURLs where the most used ones show up
882 // first.
883 static bool TemplateURLSortByUsage(const TemplateURL* a,
884 const TemplateURL* b) {
885 return a->usage_count() > b->usage_count();
886 }
887
888 void TemplateURLHandler::HandleDoSearch(const Value* content) {
889 // Extract the parameters out of the input list.
890 if (!content || !content->IsType(Value::TYPE_LIST)) {
891 NOTREACHED();
892 return;
893 }
894 const ListValue* args = static_cast<const ListValue*>(content);
895 if (args->GetSize() != 2) {
896 NOTREACHED();
897 return;
898 }
899 std::wstring keyword, search;
900 Value* value = NULL;
901 if (!args->Get(0, &value) || !value->GetAsString(&keyword)) {
902 NOTREACHED();
903 return;
904 }
905 if (!args->Get(1, &value) || !value->GetAsString(&search)) {
906 NOTREACHED();
907 return;
908 }
909
910 // Combine the keyword and search into a URL.
911 const TemplateURL* template_url =
912 template_url_model_->GetTemplateURLForKeyword(keyword);
913 if (!template_url) {
914 // The keyword seems to have changed out from under us.
915 // Not an error, but nothing we can do...
916 return;
917 }
918 const TemplateURLRef* url_ref = template_url->url();
919 if (!url_ref || !url_ref->SupportsReplacement()) {
920 NOTREACHED();
921 return;
922 }
923 GURL url = GURL(WideToUTF8(url_ref->ReplaceSearchTerms(*template_url, search,
924 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())));
925
926 if (url.is_valid()) {
927 // Record the user action
928 std::vector<const TemplateURL*> urls =
929 template_url_model_->GetTemplateURLs();
930 sort(urls.begin(), urls.end(), TemplateURLSortByUsage);
931 ListValue urls_value;
932 int item_number = 0;
933 for (size_t i = 0;
934 i < std::min<size_t>(urls.size(), kSearchURLs); ++i) {
935 if (urls[i]->usage_count() == 0)
936 break; // The remainder would be no good.
937
938 const TemplateURLRef* urlref = urls[i]->url();
939 if (!urlref)
940 continue;
941
942 if (urls[i] == template_url) {
943 UserMetrics::RecordComputedAction(
944 StringPrintf(L"NTP_SearchURL%d", item_number),
945 dom_ui_->GetProfile());
946 break;
947 }
948
949 item_number++;
950 }
951
952 // Load the URL.
953 dom_ui_->tab_contents()->OpenURL(url, GURL(), CURRENT_TAB,
954 PageTransition::LINK);
955 // We've been deleted.
956 return;
957 }
958 }
959
960 void TemplateURLHandler::OnTemplateURLModelChanged() {
961 // We've loaded some template URLs. Send them to the page.
962 std::vector<const TemplateURL*> urls = template_url_model_->GetTemplateURLs();
963 sort(urls.begin(), urls.end(), TemplateURLSortByUsage);
964 ListValue urls_value;
965 for (size_t i = 0; i < std::min<size_t>(urls.size(), kSearchURLs); ++i) {
966 if (urls[i]->usage_count() == 0)
967 break; // urls is sorted by usage count; the remainder would be no good.
968
969 const TemplateURLRef* urlref = urls[i]->url();
970 if (!urlref)
971 continue;
972 DictionaryValue* entry_value = new DictionaryValue;
973 entry_value->SetString(L"short_name", urls[i]->short_name());
974 entry_value->SetString(L"keyword", urls[i]->keyword());
975
976 const GURL& url = urls[i]->GetFavIconURL();
977 if (url.is_valid())
978 entry_value->SetString(L"favIconURL", UTF8ToWide(url.spec()));
979
980 urls_value.Append(entry_value);
981 }
982 UMA_HISTOGRAM_COUNTS("NewTabPage.SearchURLs.Total", urls_value.GetSize());
983 dom_ui_->CallJavascriptFunction(L"searchURLs", urls_value);
984 }
985
986 ///////////////////////////////////////////////////////////////////////////////
987 // RecentlyBookmarkedHandler
988
989 class RecentlyBookmarkedHandler : public DOMMessageHandler,
990 public BookmarkModelObserver {
991 public:
992 explicit RecentlyBookmarkedHandler(DOMUI* dom_ui);
993 ~RecentlyBookmarkedHandler();
994
995 // Callback which navigates to the bookmarks page.
996 void HandleShowBookmarkPage(const Value*);
997
998 // Callback for the "getRecentlyBookmarked" message.
999 // It takes no arguments.
1000 void HandleGetRecentlyBookmarked(const Value*);
1001
1002 private:
1003 void SendBookmarksToPage();
1004
1005 // BookmarkModelObserver methods. These invoke SendBookmarksToPage.
1006 virtual void Loaded(BookmarkModel* model);
1007 virtual void BookmarkNodeAdded(BookmarkModel* model,
1008 BookmarkNode* parent,
1009 int index);
1010 virtual void BookmarkNodeRemoved(BookmarkModel* model,
1011 BookmarkNode* parent,
1012 int index);
1013 virtual void BookmarkNodeChanged(BookmarkModel* model,
1014 BookmarkNode* node);
1015
1016 // These won't effect what is shown, so they do nothing.
1017 virtual void BookmarkNodeMoved(BookmarkModel* model,
1018 BookmarkNode* old_parent,
1019 int old_index,
1020 BookmarkNode* new_parent,
1021 int new_index) {}
1022 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
1023 BookmarkNode* node) {}
1024 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
1025 BookmarkNode* node) {}
1026
1027 DOMUI* dom_ui_;
1028 // The model we're getting bookmarks from. The model is owned by the Profile.
1029 BookmarkModel* model_;
1030
1031 DISALLOW_COPY_AND_ASSIGN(RecentlyBookmarkedHandler);
1032 };
1033
1034 RecentlyBookmarkedHandler::RecentlyBookmarkedHandler(DOMUI* dom_ui)
1035 : DOMMessageHandler(dom_ui),
1036 dom_ui_(dom_ui),
1037 model_(NULL) {
1038 dom_ui->RegisterMessageCallback("getRecentlyBookmarked",
1039 NewCallback(this,
1040 &RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked));
1041 }
1042
1043 RecentlyBookmarkedHandler::~RecentlyBookmarkedHandler() {
1044 if (model_)
1045 model_->RemoveObserver(this);
1046 }
1047
1048 void RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked(const Value*) {
1049 if (!model_) {
1050 model_ = dom_ui_->GetProfile()->GetBookmarkModel();
1051 model_->AddObserver(this);
1052 }
1053 // If the model is loaded, synchronously send the bookmarks down. Otherwise
1054 // when the model loads we'll send the bookmarks down.
1055 if (model_->IsLoaded())
1056 SendBookmarksToPage();
1057 }
1058
1059 void RecentlyBookmarkedHandler::SendBookmarksToPage() {
1060 std::vector<BookmarkNode*> recently_bookmarked;
1061 bookmark_utils::GetMostRecentlyAddedEntries(
1062 model_, kRecentBookmarks, &recently_bookmarked);
1063 ListValue list_value;
1064 for (size_t i = 0; i < recently_bookmarked.size(); ++i) {
1065 BookmarkNode* node = recently_bookmarked[i];
1066 DictionaryValue* entry_value = new DictionaryValue;
1067 SetURLTitleAndDirection(entry_value,
1068 WideToUTF16(node->GetTitle()), node->GetURL());
1069 entry_value->SetInteger(L"time",
1070 static_cast<int>(node->date_added().ToTimeT()));
1071 list_value.Append(entry_value);
1072 }
1073 dom_ui_->CallJavascriptFunction(L"recentlyBookmarked", list_value);
1074 }
1075
1076 void RecentlyBookmarkedHandler::Loaded(BookmarkModel* model) {
1077 SendBookmarksToPage();
1078 }
1079
1080 void RecentlyBookmarkedHandler::BookmarkNodeAdded(BookmarkModel* model,
1081 BookmarkNode* parent,
1082 int index) {
1083 SendBookmarksToPage();
1084 }
1085
1086 void RecentlyBookmarkedHandler::BookmarkNodeRemoved(BookmarkModel* model,
1087 BookmarkNode* parent,
1088 int index) {
1089 SendBookmarksToPage();
1090 }
1091
1092 void RecentlyBookmarkedHandler::BookmarkNodeChanged(BookmarkModel* model,
1093 BookmarkNode* node) {
1094 SendBookmarksToPage();
1095 }
1096
1097 ///////////////////////////////////////////////////////////////////////////////
1098 // RecentlyClosedTabsHandler 821 // RecentlyClosedTabsHandler
1099 822
1100 class RecentlyClosedTabsHandler : public DOMMessageHandler, 823 class RecentlyClosedTabsHandler : public DOMMessageHandler,
1101 public TabRestoreService::Observer { 824 public TabRestoreService::Observer {
1102 public: 825 public:
1103 explicit RecentlyClosedTabsHandler(DOMUI* dom_ui); 826 explicit RecentlyClosedTabsHandler(DOMUI* dom_ui);
1104 virtual ~RecentlyClosedTabsHandler(); 827 virtual ~RecentlyClosedTabsHandler();
1105 828
1106 // Callback for the "reopenTab" message. Rewrites the history of the 829 // Callback for the "reopenTab" message. Rewrites the history of the
1107 // currently displayed tab to be the one in TabRestoreService with a 830 // currently displayed tab to be the one in TabRestoreService with a
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 delete tab_values; 998 delete tab_values;
1276 return false; 999 return false;
1277 } 1000 }
1278 1001
1279 dictionary->SetString(L"type", L"window"); 1002 dictionary->SetString(L"type", L"window");
1280 dictionary->Set(L"tabs", tab_values); 1003 dictionary->Set(L"tabs", tab_values);
1281 return true; 1004 return true;
1282 } 1005 }
1283 1006
1284 /////////////////////////////////////////////////////////////////////////////// 1007 ///////////////////////////////////////////////////////////////////////////////
1285 // HistoryHandler
1286
1287 class HistoryHandler : public DOMMessageHandler {
1288 public:
1289 explicit HistoryHandler(DOMUI* dom_ui);
1290
1291 // Callback which navigates to the history page and performs a search.
1292 void HandleSearchHistoryPage(const Value* content);
1293
1294 private:
1295 DOMUI* dom_ui_;
1296
1297 DISALLOW_COPY_AND_ASSIGN(HistoryHandler);
1298 };
1299
1300 HistoryHandler::HistoryHandler(DOMUI* dom_ui)
1301 : DOMMessageHandler(dom_ui),
1302 dom_ui_(dom_ui) {
1303 dom_ui->RegisterMessageCallback("searchHistoryPage",
1304 NewCallback(this, &HistoryHandler::HandleSearchHistoryPage));
1305 }
1306
1307 void HistoryHandler::HandleSearchHistoryPage(const Value* content) {
1308 if (content && content->GetType() == Value::TYPE_LIST) {
1309 const ListValue* list_value = static_cast<const ListValue*>(content);
1310 Value* list_member;
1311 if (list_value->Get(0, &list_member) &&
1312 list_member->GetType() == Value::TYPE_STRING) {
1313 const StringValue* string_value =
1314 static_cast<const StringValue*>(list_member);
1315 std::wstring wstring_value;
1316 if (string_value->GetAsString(&wstring_value)) {
1317 UserMetrics::RecordAction(L"NTP_SearchHistory", dom_ui_->GetProfile());
1318 dom_ui_->tab_contents()->controller().LoadURL(
1319 HistoryUI::GetHistoryURLWithSearchText(wstring_value),
1320 GURL(),
1321 PageTransition::LINK);
1322 // We are deleted by LoadURL, so do not call anything else.
1323 }
1324 }
1325 }
1326 }
1327
1328 ///////////////////////////////////////////////////////////////////////////////
1329 // MetricsHandler 1008 // MetricsHandler
1330 1009
1331 // Let the page contents record UMA actions. Only use when you can't do it from 1010 // Let the page contents record UMA actions. Only use when you can't do it from
1332 // C++. For example, we currently use it to let the NTP log the postion of the 1011 // C++. For example, we currently use it to let the NTP log the postion of the
1333 // Most Visited or Bookmark the user clicked on, as we don't get that 1012 // Most Visited or Bookmark the user clicked on, as we don't get that
1334 // information through RequestOpenURL. You will need to update the metrics 1013 // information through RequestOpenURL. You will need to update the metrics
1335 // dashboard with the action names you use, as our processor won't catch that 1014 // dashboard with the action names you use, as our processor won't catch that
1336 // information (treat it as RecordComputedMetrics) 1015 // information (treat it as RecordComputedMetrics)
1337 class MetricsHandler : public DOMMessageHandler { 1016 class MetricsHandler : public DOMMessageHandler {
1338 public: 1017 public:
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 if (GetProfile()->IsOffTheRecord()) { 1081 if (GetProfile()->IsOffTheRecord()) {
1403 incognito_ = true; 1082 incognito_ = true;
1404 1083
1405 IncognitoTabHTMLSource* html_source = new IncognitoTabHTMLSource(); 1084 IncognitoTabHTMLSource* html_source = new IncognitoTabHTMLSource();
1406 1085
1407 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, 1086 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
1408 NewRunnableMethod(&chrome_url_data_manager, 1087 NewRunnableMethod(&chrome_url_data_manager,
1409 &ChromeURLDataManager::AddDataSource, 1088 &ChromeURLDataManager::AddDataSource,
1410 html_source)); 1089 html_source));
1411 } else { 1090 } else {
1091 AddMessageHandler(new MostVisitedHandler(this));
1092 AddMessageHandler(new ShownSectionsHandler(this));
1093 AddMessageHandler(new RecentlyClosedTabsHandler(this));
1094 AddMessageHandler(new MetricsHandler(this));
1412 1095
1413 if (EnableNewNewTabPage()) { 1096 // TODO(arv): What if this is not enabled?
1414 DownloadManager* dlm = GetProfile()->GetDownloadManager();
1415 DownloadsDOMHandler* downloads_handler =
1416 new DownloadsDOMHandler(this, dlm);
1417 AddMessageHandler(downloads_handler);
1418 downloads_handler->Init();
1419
1420 AddMessageHandler(new ShownSectionsHandler(this));
1421 }
1422
1423 if (EnableWebResources()) 1097 if (EnableWebResources())
1424 AddMessageHandler(new TipsHandler(this)); 1098 AddMessageHandler(new TipsHandler(this));
1425 1099
1426 AddMessageHandler(new TemplateURLHandler(this)); 1100 DownloadManager* dlm = GetProfile()->GetDownloadManager();
1427 AddMessageHandler(new MostVisitedHandler(this)); 1101 DownloadsDOMHandler* downloads_handler =
1428 AddMessageHandler(new RecentlyBookmarkedHandler(this)); 1102 new DownloadsDOMHandler(this, dlm);
1429 AddMessageHandler(new RecentlyClosedTabsHandler(this)); 1103 AddMessageHandler(downloads_handler);
1430 AddMessageHandler(new HistoryHandler(this)); 1104 downloads_handler->Init();
1431 AddMessageHandler(new MetricsHandler(this));
1432 #ifdef CHROME_PERSONALIZATION 1105 #ifdef CHROME_PERSONALIZATION
1433 if (!Personalization::IsP13NDisabled(GetProfile())) { 1106 if (!Personalization::IsP13NDisabled(GetProfile())) {
1434 AddMessageHandler(Personalization::CreateNewTabPageHandler(this)); 1107 AddMessageHandler(Personalization::CreateNewTabPageHandler(this));
1435 } 1108 }
1436 #endif 1109 #endif
1437 1110
1438 // In testing mode there may not be an I/O thread. 1111 // In testing mode there may not be an I/O thread.
1439 if (g_browser_process->io_thread()) { 1112 if (g_browser_process->io_thread()) {
1440 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, 1113 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
1441 NewRunnableMethod(&chrome_url_data_manager, 1114 NewRunnableMethod(&chrome_url_data_manager,
(...skipping 29 matching lines...) Expand all
1471 CallJavascriptFunction(L"bookmarkBarAttached"); 1144 CallJavascriptFunction(L"bookmarkBarAttached");
1472 else 1145 else
1473 CallJavascriptFunction(L"bookmarkBarDetached"); 1146 CallJavascriptFunction(L"bookmarkBarDetached");
1474 } 1147 }
1475 } 1148 }
1476 1149
1477 1150
1478 // static 1151 // static
1479 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { 1152 void NewTabUI::RegisterUserPrefs(PrefService* prefs) {
1480 MostVisitedHandler::RegisterUserPrefs(prefs); 1153 MostVisitedHandler::RegisterUserPrefs(prefs);
1154 ShownSectionsHandler::RegisterUserPrefs(prefs);
1481 if (NewTabUI::EnableWebResources()) 1155 if (NewTabUI::EnableWebResources())
1482 TipsHandler::RegisterUserPrefs(prefs); 1156 TipsHandler::RegisterUserPrefs(prefs);
1483 if (NewTabUI::EnableNewNewTabPage())
1484 ShownSectionsHandler::RegisterUserPrefs(prefs);
1485 }
1486
1487 // static
1488 bool NewTabUI::EnableNewNewTabPage() {
1489 const CommandLine* command_line = CommandLine::ForCurrentProcess();
1490 return command_line->HasSwitch(switches::kNewNewTabPage);
1491 } 1157 }
1492 1158
1493 bool NewTabUI::EnableWebResources() { 1159 bool NewTabUI::EnableWebResources() {
1494 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 1160 const CommandLine* command_line = CommandLine::ForCurrentProcess();
1495 return command_line->HasSwitch(switches::kWebResources); 1161 return command_line->HasSwitch(switches::kWebResources);
1496 } 1162 }
1497 1163
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698