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

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

Issue 131094: Add GetMessageHandlers to HtmlDialogUIDelegate to allow... (Closed) Base URL: svn://chrome-svn/chrome/trunk/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/browser/dom_ui/html_dialog_ui.cc ('k') | chrome/browser/dom_ui/shown_sections_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 SendResponse(request_id, html_bytes); 451 SendResponse(request_id, html_bytes);
452 } 452 }
453 453
454 /////////////////////////////////////////////////////////////////////////////// 454 ///////////////////////////////////////////////////////////////////////////////
455 // MostVisitedHandler 455 // MostVisitedHandler
456 456
457 // The handler for Javascript messages related to the "most visited" view. 457 // The handler for Javascript messages related to the "most visited" view.
458 class MostVisitedHandler : public DOMMessageHandler, 458 class MostVisitedHandler : public DOMMessageHandler,
459 public NotificationObserver { 459 public NotificationObserver {
460 public: 460 public:
461 explicit MostVisitedHandler(DOMUI* dom_ui); 461 MostVisitedHandler() : url_blacklist_(NULL), pinned_urls_(NULL) { }
462 virtual ~MostVisitedHandler(); 462 virtual ~MostVisitedHandler() { }
463
464 // DOMMessageHandler override and implementation.
465 virtual DOMMessageHandler* Attach(DOMUI* dom_ui);
466 virtual void RegisterMessages();
463 467
464 // Callback for the "getMostVisited" message. 468 // Callback for the "getMostVisited" message.
465 void HandleGetMostVisited(const Value* value); 469 void HandleGetMostVisited(const Value* value);
466 470
467 // Callback for the "blacklistURLFromMostVisited" message. 471 // Callback for the "blacklistURLFromMostVisited" message.
468 void HandleBlacklistURL(const Value* url); 472 void HandleBlacklistURL(const Value* url);
469 473
470 // Callback for the "removeURLsFromMostVisitedBlacklist" message. 474 // Callback for the "removeURLsFromMostVisitedBlacklist" message.
471 void HandleRemoveURLsFromBlacklist(const Value* url); 475 void HandleRemoveURLsFromBlacklist(const Value* url);
472 476
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 DictionaryValue* url_blacklist_; 530 DictionaryValue* url_blacklist_;
527 531
528 // This is a dictionary for the pinned URLs for the the most visited part of 532 // This is a dictionary for the pinned URLs for the the most visited part of
529 // the new tab page. The key of the dictionary is a hash of the URL and the 533 // the new tab page. The key of the dictionary is a hash of the URL and the
530 // value is a dictionary with title, url and index. 534 // value is a dictionary with title, url and index.
531 DictionaryValue* pinned_urls_; 535 DictionaryValue* pinned_urls_;
532 536
533 DISALLOW_COPY_AND_ASSIGN(MostVisitedHandler); 537 DISALLOW_COPY_AND_ASSIGN(MostVisitedHandler);
534 }; 538 };
535 539
536 MostVisitedHandler::MostVisitedHandler(DOMUI* dom_ui) 540 DOMMessageHandler* MostVisitedHandler::Attach(DOMUI* dom_ui) {
537 : DOMMessageHandler(dom_ui) { 541 url_blacklist_ = dom_ui->GetProfile()->GetPrefs()->
538 // Register ourselves as the handler for the "mostvisited" message from
539 // Javascript.
540 dom_ui_->RegisterMessageCallback("getMostVisited",
541 NewCallback(this, &MostVisitedHandler::HandleGetMostVisited));
542
543 // Register ourselves for any most-visited item blacklisting.
544 dom_ui_->RegisterMessageCallback("blacklistURLFromMostVisited",
545 NewCallback(this, &MostVisitedHandler::HandleBlacklistURL));
546 dom_ui_->RegisterMessageCallback("removeURLsFromMostVisitedBlacklist",
547 NewCallback(this, &MostVisitedHandler::HandleRemoveURLsFromBlacklist));
548 dom_ui_->RegisterMessageCallback("clearMostVisitedURLsBlacklist",
549 NewCallback(this, &MostVisitedHandler::HandleClearBlacklist));
550
551 url_blacklist_ = dom_ui_->GetProfile()->GetPrefs()->
552 GetMutableDictionary(prefs::kNTPMostVisitedURLsBlacklist); 542 GetMutableDictionary(prefs::kNTPMostVisitedURLsBlacklist);
553 543 pinned_urls_ = dom_ui->GetProfile()->GetPrefs()->
554 // Register ourself for pinned URL messages. 544 GetMutableDictionary(prefs::kNTPMostVisitedPinnedURLs);
555 dom_ui->RegisterMessageCallback("addPinnedURL",
556 NewCallback(this, &MostVisitedHandler::HandleAddPinnedURL));
557 dom_ui->RegisterMessageCallback("removePinnedURL",
558 NewCallback(this, &MostVisitedHandler::HandleRemovePinnedURL));
559
560 pinned_urls_ = dom_ui_->GetProfile()->GetPrefs()->
561 GetMutableDictionary(prefs::kNTPMostVisitedPinnedURLs);
562
563 // Set up our sources for thumbnail and favicon data. Since we may be in 545 // Set up our sources for thumbnail and favicon data. Since we may be in
564 // testing mode with no I/O thread, only add our handler when an I/O thread 546 // testing mode with no I/O thread, only add our handler when an I/O thread
565 // exists. Ownership is passed to the ChromeURLDataManager. 547 // exists. Ownership is passed to the ChromeURLDataManager.
566 if (g_browser_process->io_thread()) { 548 if (g_browser_process->io_thread()) {
567 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, 549 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
568 NewRunnableMethod(&chrome_url_data_manager, 550 NewRunnableMethod(&chrome_url_data_manager,
569 &ChromeURLDataManager::AddDataSource, 551 &ChromeURLDataManager::AddDataSource,
570 new DOMUIThumbnailSource(dom_ui->GetProfile()))); 552 new DOMUIThumbnailSource(dom_ui->GetProfile())));
571 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, 553 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
572 NewRunnableMethod(&chrome_url_data_manager, 554 NewRunnableMethod(&chrome_url_data_manager,
573 &ChromeURLDataManager::AddDataSource, 555 &ChromeURLDataManager::AddDataSource,
574 new DOMUIFavIconSource(dom_ui->GetProfile()))); 556 new DOMUIFavIconSource(dom_ui->GetProfile())));
575 } 557 }
576 558
577 // Get notifications when history is cleared. 559 // Get notifications when history is cleared.
578 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, 560 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED,
579 Source<Profile>(dom_ui_->GetProfile())); 561 Source<Profile>(dom_ui->GetProfile()));
562
563 return DOMMessageHandler::Attach(dom_ui);
580 } 564 }
581 565
582 MostVisitedHandler::~MostVisitedHandler() { 566 void MostVisitedHandler::RegisterMessages() {
567 // Register ourselves as the handler for the "mostvisited" message from
568 // Javascript.
569 dom_ui_->RegisterMessageCallback("getMostVisited",
570 NewCallback(this, &MostVisitedHandler::HandleGetMostVisited));
571
572 // Register ourselves for any most-visited item blacklisting.
573 dom_ui_->RegisterMessageCallback("blacklistURLFromMostVisited",
574 NewCallback(this, &MostVisitedHandler::HandleBlacklistURL));
575 dom_ui_->RegisterMessageCallback("removeURLsFromMostVisitedBlacklist",
576 NewCallback(this, &MostVisitedHandler::HandleRemoveURLsFromBlacklist));
577 dom_ui_->RegisterMessageCallback("clearMostVisitedURLsBlacklist",
578 NewCallback(this, &MostVisitedHandler::HandleClearBlacklist));
579
580 // Register ourself for pinned URL messages.
581 dom_ui_->RegisterMessageCallback("addPinnedURL",
582 NewCallback(this, &MostVisitedHandler::HandleAddPinnedURL));
583 dom_ui_->RegisterMessageCallback("removePinnedURL",
584 NewCallback(this, &MostVisitedHandler::HandleRemovePinnedURL));
583 } 585 }
584 586
585 void MostVisitedHandler::HandleGetMostVisited(const Value* value) { 587 void MostVisitedHandler::HandleGetMostVisited(const Value* value) {
586 const int kMostVisitedCount = 9; 588 const int kMostVisitedCount = 9;
587 // Let's query for the number of items we want plus the blacklist size as 589 // Let's query for the number of items we want plus the blacklist size as
588 // we'll be filtering-out the returned list with the blacklist URLs. 590 // we'll be filtering-out the returned list with the blacklist URLs.
589 // We do not subtract the number of pinned URLs we have because the 591 // We do not subtract the number of pinned URLs we have because the
590 // HistoryService does not know about those. 592 // HistoryService does not know about those.
591 int result_count = kMostVisitedCount + url_blacklist_->GetSize(); 593 int result_count = kMostVisitedCount + url_blacklist_->GetSize();
592 HistoryService* hs = 594 HistoryService* hs =
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedPinnedURLs); 823 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedPinnedURLs);
822 } 824 }
823 825
824 /////////////////////////////////////////////////////////////////////////////// 826 ///////////////////////////////////////////////////////////////////////////////
825 // TemplateURLHandler 827 // TemplateURLHandler
826 828
827 // The handler for Javascript messages related to the "common searches" view. 829 // The handler for Javascript messages related to the "common searches" view.
828 class TemplateURLHandler : public DOMMessageHandler, 830 class TemplateURLHandler : public DOMMessageHandler,
829 public TemplateURLModelObserver { 831 public TemplateURLModelObserver {
830 public: 832 public:
831 explicit TemplateURLHandler(DOMUI* dom_ui); 833 TemplateURLHandler() : DOMMessageHandler(), template_url_model_(NULL) { }
832 virtual ~TemplateURLHandler(); 834 virtual ~TemplateURLHandler();
833 835
836 // DOMMessageHandler implementation.
837 virtual void RegisterMessages();
838
834 // Callback for the "getMostSearched" message, sent when the page requests 839 // Callback for the "getMostSearched" message, sent when the page requests
835 // the list of available searches. 840 // the list of available searches.
836 void HandleGetMostSearched(const Value* content); 841 void HandleGetMostSearched(const Value* content);
837 // Callback for the "doSearch" message, sent when the user wants to 842 // Callback for the "doSearch" message, sent when the user wants to
838 // run a search. Content of the message is an array containing 843 // run a search. Content of the message is an array containing
839 // [<the search keyword>, <the search term>]. 844 // [<the search keyword>, <the search term>].
840 void HandleDoSearch(const Value* content); 845 void HandleDoSearch(const Value* content);
841 846
842 // TemplateURLModelObserver implementation. 847 // TemplateURLModelObserver implementation.
843 virtual void OnTemplateURLModelChanged(); 848 virtual void OnTemplateURLModelChanged();
844 849
845 private: 850 private:
846 DOMUI* dom_ui_;
847 TemplateURLModel* template_url_model_; // Owned by profile. 851 TemplateURLModel* template_url_model_; // Owned by profile.
848 852
849 DISALLOW_COPY_AND_ASSIGN(TemplateURLHandler); 853 DISALLOW_COPY_AND_ASSIGN(TemplateURLHandler);
850 }; 854 };
851 855
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() { 856 TemplateURLHandler::~TemplateURLHandler() {
863 if (template_url_model_) 857 if (template_url_model_)
864 template_url_model_->RemoveObserver(this); 858 template_url_model_->RemoveObserver(this);
865 } 859 }
866 860
861 void TemplateURLHandler::RegisterMessages() {
862 dom_ui_->RegisterMessageCallback("getMostSearched",
863 NewCallback(this, &TemplateURLHandler::HandleGetMostSearched));
864 dom_ui_->RegisterMessageCallback("doSearch",
865 NewCallback(this, &TemplateURLHandler::HandleDoSearch));
866 }
867
867 void TemplateURLHandler::HandleGetMostSearched(const Value* content) { 868 void TemplateURLHandler::HandleGetMostSearched(const Value* content) {
868 // The page Javascript has requested the list of keyword searches. 869 // The page Javascript has requested the list of keyword searches.
869 // Start loading them from the template URL backend. 870 // Start loading them from the template URL backend.
870 if (!template_url_model_) { 871 if (!template_url_model_) {
871 template_url_model_ = dom_ui_->GetProfile()->GetTemplateURLModel(); 872 template_url_model_ = dom_ui_->GetProfile()->GetTemplateURLModel();
872 template_url_model_->AddObserver(this); 873 template_url_model_->AddObserver(this);
873 } 874 }
874 if (template_url_model_->loaded()) { 875 if (template_url_model_->loaded()) {
875 OnTemplateURLModelChanged(); 876 OnTemplateURLModelChanged();
876 } else { 877 } else {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 UMA_HISTOGRAM_COUNTS("NewTabPage.SearchURLs.Total", urls_value.GetSize()); 983 UMA_HISTOGRAM_COUNTS("NewTabPage.SearchURLs.Total", urls_value.GetSize());
983 dom_ui_->CallJavascriptFunction(L"searchURLs", urls_value); 984 dom_ui_->CallJavascriptFunction(L"searchURLs", urls_value);
984 } 985 }
985 986
986 /////////////////////////////////////////////////////////////////////////////// 987 ///////////////////////////////////////////////////////////////////////////////
987 // RecentlyBookmarkedHandler 988 // RecentlyBookmarkedHandler
988 989
989 class RecentlyBookmarkedHandler : public DOMMessageHandler, 990 class RecentlyBookmarkedHandler : public DOMMessageHandler,
990 public BookmarkModelObserver { 991 public BookmarkModelObserver {
991 public: 992 public:
992 explicit RecentlyBookmarkedHandler(DOMUI* dom_ui); 993 RecentlyBookmarkedHandler() : model_(NULL) { }
993 ~RecentlyBookmarkedHandler(); 994 virtual ~RecentlyBookmarkedHandler();
995
996 // DOMMessageHandler implementation.
997 virtual void RegisterMessages();
994 998
995 // Callback which navigates to the bookmarks page. 999 // Callback which navigates to the bookmarks page.
996 void HandleShowBookmarkPage(const Value*); 1000 void HandleShowBookmarkPage(const Value*);
997 1001
998 // Callback for the "getRecentlyBookmarked" message. 1002 // Callback for the "getRecentlyBookmarked" message.
999 // It takes no arguments. 1003 // It takes no arguments.
1000 void HandleGetRecentlyBookmarked(const Value*); 1004 void HandleGetRecentlyBookmarked(const Value*);
1001 1005
1002 private: 1006 private:
1003 void SendBookmarksToPage(); 1007 void SendBookmarksToPage();
(...skipping 13 matching lines...) Expand all
1017 virtual void BookmarkNodeMoved(BookmarkModel* model, 1021 virtual void BookmarkNodeMoved(BookmarkModel* model,
1018 BookmarkNode* old_parent, 1022 BookmarkNode* old_parent,
1019 int old_index, 1023 int old_index,
1020 BookmarkNode* new_parent, 1024 BookmarkNode* new_parent,
1021 int new_index) {} 1025 int new_index) {}
1022 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, 1026 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
1023 BookmarkNode* node) {} 1027 BookmarkNode* node) {}
1024 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, 1028 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
1025 BookmarkNode* node) {} 1029 BookmarkNode* node) {}
1026 1030
1027 DOMUI* dom_ui_;
1028 // The model we're getting bookmarks from. The model is owned by the Profile. 1031 // The model we're getting bookmarks from. The model is owned by the Profile.
1029 BookmarkModel* model_; 1032 BookmarkModel* model_;
1030 1033
1031 DISALLOW_COPY_AND_ASSIGN(RecentlyBookmarkedHandler); 1034 DISALLOW_COPY_AND_ASSIGN(RecentlyBookmarkedHandler);
1032 }; 1035 };
1033 1036
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() { 1037 RecentlyBookmarkedHandler::~RecentlyBookmarkedHandler() {
1044 if (model_) 1038 if (model_)
1045 model_->RemoveObserver(this); 1039 model_->RemoveObserver(this);
1046 } 1040 }
1047 1041
1042 void RecentlyBookmarkedHandler::RegisterMessages() {
1043 dom_ui_->RegisterMessageCallback("getRecentlyBookmarked",
1044 NewCallback(this,
1045 &RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked));
1046 }
1047
1048 void RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked(const Value*) { 1048 void RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked(const Value*) {
1049 if (!model_) { 1049 if (!model_) {
1050 model_ = dom_ui_->GetProfile()->GetBookmarkModel(); 1050 model_ = dom_ui_->GetProfile()->GetBookmarkModel();
1051 model_->AddObserver(this); 1051 model_->AddObserver(this);
1052 } 1052 }
1053 // If the model is loaded, synchronously send the bookmarks down. Otherwise 1053 // If the model is loaded, synchronously send the bookmarks down. Otherwise
1054 // when the model loads we'll send the bookmarks down. 1054 // when the model loads we'll send the bookmarks down.
1055 if (model_->IsLoaded()) 1055 if (model_->IsLoaded())
1056 SendBookmarksToPage(); 1056 SendBookmarksToPage();
1057 } 1057 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 BookmarkNode* node) { 1093 BookmarkNode* node) {
1094 SendBookmarksToPage(); 1094 SendBookmarksToPage();
1095 } 1095 }
1096 1096
1097 /////////////////////////////////////////////////////////////////////////////// 1097 ///////////////////////////////////////////////////////////////////////////////
1098 // RecentlyClosedTabsHandler 1098 // RecentlyClosedTabsHandler
1099 1099
1100 class RecentlyClosedTabsHandler : public DOMMessageHandler, 1100 class RecentlyClosedTabsHandler : public DOMMessageHandler,
1101 public TabRestoreService::Observer { 1101 public TabRestoreService::Observer {
1102 public: 1102 public:
1103 explicit RecentlyClosedTabsHandler(DOMUI* dom_ui); 1103 RecentlyClosedTabsHandler() : tab_restore_service_(NULL) { }
1104 virtual ~RecentlyClosedTabsHandler(); 1104 virtual ~RecentlyClosedTabsHandler();
1105 1105
1106 // DOMMessageHandler implementation.
1107 virtual void RegisterMessages();
1108
1106 // Callback for the "reopenTab" message. Rewrites the history of the 1109 // Callback for the "reopenTab" message. Rewrites the history of the
1107 // currently displayed tab to be the one in TabRestoreService with a 1110 // currently displayed tab to be the one in TabRestoreService with a
1108 // history of a session passed in through the content pointer. 1111 // history of a session passed in through the content pointer.
1109 void HandleReopenTab(const Value* content); 1112 void HandleReopenTab(const Value* content);
1110 1113
1111 // Callback for the "getRecentlyClosedTabs" message. 1114 // Callback for the "getRecentlyClosedTabs" message.
1112 void HandleGetRecentlyClosedTabs(const Value* content); 1115 void HandleGetRecentlyClosedTabs(const Value* content);
1113 1116
1114 // Observer callback for TabRestoreService::Observer. Sends data on 1117 // Observer callback for TabRestoreService::Observer. Sends data on
1115 // recently closed tabs to the javascript side of this page to 1118 // recently closed tabs to the javascript side of this page to
1116 // display to the user. 1119 // display to the user.
1117 virtual void TabRestoreServiceChanged(TabRestoreService* service); 1120 virtual void TabRestoreServiceChanged(TabRestoreService* service);
1118 1121
1119 // Observer callback to notice when our associated TabRestoreService 1122 // Observer callback to notice when our associated TabRestoreService
1120 // is destroyed. 1123 // is destroyed.
1121 virtual void TabRestoreServiceDestroyed(TabRestoreService* service); 1124 virtual void TabRestoreServiceDestroyed(TabRestoreService* service);
1122 1125
1123 private: 1126 private:
1124 // Converts a closed tab to the value sent down to the NTP. Returns true on 1127 // Converts a closed tab to the value sent down to the NTP. Returns true on
1125 // success, false if the value shouldn't be sent down. 1128 // success, false if the value shouldn't be sent down.
1126 bool TabToValue(const TabRestoreService::Tab& tab, 1129 bool TabToValue(const TabRestoreService::Tab& tab,
1127 DictionaryValue* dictionary); 1130 DictionaryValue* dictionary);
1128 1131
1129 // Converts a closed window to the value sent down to the NTP. Returns true 1132 // Converts a closed window to the value sent down to the NTP. Returns true
1130 // on success, false if the value shouldn't be sent down. 1133 // on success, false if the value shouldn't be sent down.
1131 bool WindowToValue(const TabRestoreService::Window& window, 1134 bool WindowToValue(const TabRestoreService::Window& window,
1132 DictionaryValue* dictionary); 1135 DictionaryValue* dictionary);
1133 1136
1134 DOMUI* dom_ui_;
1135
1136 // TabRestoreService that we are observing. 1137 // TabRestoreService that we are observing.
1137 TabRestoreService* tab_restore_service_; 1138 TabRestoreService* tab_restore_service_;
1138 1139
1139 DISALLOW_COPY_AND_ASSIGN(RecentlyClosedTabsHandler); 1140 DISALLOW_COPY_AND_ASSIGN(RecentlyClosedTabsHandler);
1140 }; 1141 };
1141 1142
1142 RecentlyClosedTabsHandler::RecentlyClosedTabsHandler(DOMUI* dom_ui) 1143 void RecentlyClosedTabsHandler::RegisterMessages() {
1143 : DOMMessageHandler(dom_ui), 1144 dom_ui_->RegisterMessageCallback("getRecentlyClosedTabs",
1144 dom_ui_(dom_ui),
1145 tab_restore_service_(NULL) {
1146 dom_ui->RegisterMessageCallback("getRecentlyClosedTabs",
1147 NewCallback(this, 1145 NewCallback(this,
1148 &RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs)); 1146 &RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs));
1149 dom_ui->RegisterMessageCallback("reopenTab", 1147 dom_ui_->RegisterMessageCallback("reopenTab",
1150 NewCallback(this, &RecentlyClosedTabsHandler::HandleReopenTab)); 1148 NewCallback(this, &RecentlyClosedTabsHandler::HandleReopenTab));
1151 } 1149 }
1152 1150
1153 RecentlyClosedTabsHandler::~RecentlyClosedTabsHandler() { 1151 RecentlyClosedTabsHandler::~RecentlyClosedTabsHandler() {
1154 if (tab_restore_service_) 1152 if (tab_restore_service_)
1155 tab_restore_service_->RemoveObserver(this); 1153 tab_restore_service_->RemoveObserver(this);
1156 } 1154 }
1157 1155
1158 void RecentlyClosedTabsHandler::HandleReopenTab(const Value* content) { 1156 void RecentlyClosedTabsHandler::HandleReopenTab(const Value* content) {
1159 Browser* browser = Browser::GetBrowserForController( 1157 Browser* browser = Browser::GetBrowserForController(
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 dictionary->SetString(L"type", L"window"); 1277 dictionary->SetString(L"type", L"window");
1280 dictionary->Set(L"tabs", tab_values); 1278 dictionary->Set(L"tabs", tab_values);
1281 return true; 1279 return true;
1282 } 1280 }
1283 1281
1284 /////////////////////////////////////////////////////////////////////////////// 1282 ///////////////////////////////////////////////////////////////////////////////
1285 // HistoryHandler 1283 // HistoryHandler
1286 1284
1287 class HistoryHandler : public DOMMessageHandler { 1285 class HistoryHandler : public DOMMessageHandler {
1288 public: 1286 public:
1289 explicit HistoryHandler(DOMUI* dom_ui); 1287 HistoryHandler() { }
1288 virtual ~HistoryHandler() { }
1289
1290 // DOMMessageHandler implementation.
1291 virtual void RegisterMessages();
1290 1292
1291 // Callback which navigates to the history page and performs a search. 1293 // Callback which navigates to the history page and performs a search.
1292 void HandleSearchHistoryPage(const Value* content); 1294 void HandleSearchHistoryPage(const Value* content);
1293 1295
1294 private: 1296 private:
1295 DOMUI* dom_ui_;
1296 1297
1297 DISALLOW_COPY_AND_ASSIGN(HistoryHandler); 1298 DISALLOW_COPY_AND_ASSIGN(HistoryHandler);
1298 }; 1299 };
1299 1300
1300 HistoryHandler::HistoryHandler(DOMUI* dom_ui) 1301 void HistoryHandler::RegisterMessages() {
1301 : DOMMessageHandler(dom_ui), 1302 dom_ui_->RegisterMessageCallback("searchHistoryPage",
1302 dom_ui_(dom_ui) {
1303 dom_ui->RegisterMessageCallback("searchHistoryPage",
1304 NewCallback(this, &HistoryHandler::HandleSearchHistoryPage)); 1303 NewCallback(this, &HistoryHandler::HandleSearchHistoryPage));
1305 } 1304 }
1306 1305
1307 void HistoryHandler::HandleSearchHistoryPage(const Value* content) { 1306 void HistoryHandler::HandleSearchHistoryPage(const Value* content) {
1308 if (content && content->GetType() == Value::TYPE_LIST) { 1307 if (content && content->GetType() == Value::TYPE_LIST) {
1309 const ListValue* list_value = static_cast<const ListValue*>(content); 1308 const ListValue* list_value = static_cast<const ListValue*>(content);
1310 Value* list_member; 1309 Value* list_member;
1311 if (list_value->Get(0, &list_member) && 1310 if (list_value->Get(0, &list_member) &&
1312 list_member->GetType() == Value::TYPE_STRING) { 1311 list_member->GetType() == Value::TYPE_STRING) {
1313 const StringValue* string_value = 1312 const StringValue* string_value =
(...skipping 15 matching lines...) Expand all
1329 // MetricsHandler 1328 // MetricsHandler
1330 1329
1331 // Let the page contents record UMA actions. Only use when you can't do it from 1330 // 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 1331 // 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 1332 // 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 1333 // 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 1334 // dashboard with the action names you use, as our processor won't catch that
1336 // information (treat it as RecordComputedMetrics) 1335 // information (treat it as RecordComputedMetrics)
1337 class MetricsHandler : public DOMMessageHandler { 1336 class MetricsHandler : public DOMMessageHandler {
1338 public: 1337 public:
1339 explicit MetricsHandler(DOMUI* dom_ui); 1338 MetricsHandler() { }
1340 1339 virtual ~MetricsHandler() { }
1340
1341 // DOMMessageHandler implementation.
1342 virtual void RegisterMessages();
1343
1341 // Callback which records a user action. 1344 // Callback which records a user action.
1342 void HandleMetrics(const Value* content); 1345 void HandleMetrics(const Value* content);
1343 1346
1344 private: 1347 private:
1345 DOMUI* dom_ui_;
1346 1348
1347 DISALLOW_COPY_AND_ASSIGN(MetricsHandler); 1349 DISALLOW_COPY_AND_ASSIGN(MetricsHandler);
1348 }; 1350 };
1349 1351
1350 MetricsHandler::MetricsHandler(DOMUI* dom_ui) 1352 void MetricsHandler::RegisterMessages() {
1351 : DOMMessageHandler(dom_ui), 1353 dom_ui_->RegisterMessageCallback("metrics",
1352 dom_ui_(dom_ui) {
1353 dom_ui->RegisterMessageCallback("metrics",
1354 NewCallback(this, &MetricsHandler::HandleMetrics)); 1354 NewCallback(this, &MetricsHandler::HandleMetrics));
1355 } 1355 }
1356 1356
1357 void MetricsHandler::HandleMetrics(const Value* content) { 1357 void MetricsHandler::HandleMetrics(const Value* content) {
1358 if (content && content->GetType() == Value::TYPE_LIST) { 1358 if (content && content->GetType() == Value::TYPE_LIST) {
1359 const ListValue* list_value = static_cast<const ListValue*>(content); 1359 const ListValue* list_value = static_cast<const ListValue*>(content);
1360 Value* list_member; 1360 Value* list_member;
1361 if (list_value->Get(0, &list_member) && 1361 if (list_value->Get(0, &list_member) &&
1362 list_member->GetType() == Value::TYPE_STRING) { 1362 list_member->GetType() == Value::TYPE_STRING) {
1363 const StringValue* string_value = 1363 const StringValue* string_value =
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 1406
1407 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, 1407 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
1408 NewRunnableMethod(&chrome_url_data_manager, 1408 NewRunnableMethod(&chrome_url_data_manager,
1409 &ChromeURLDataManager::AddDataSource, 1409 &ChromeURLDataManager::AddDataSource,
1410 html_source)); 1410 html_source));
1411 } else { 1411 } else {
1412 1412
1413 if (EnableNewNewTabPage()) { 1413 if (EnableNewNewTabPage()) {
1414 DownloadManager* dlm = GetProfile()->GetDownloadManager(); 1414 DownloadManager* dlm = GetProfile()->GetDownloadManager();
1415 DownloadsDOMHandler* downloads_handler = 1415 DownloadsDOMHandler* downloads_handler =
1416 new DownloadsDOMHandler(this, dlm); 1416 new DownloadsDOMHandler(dlm);
1417 downloads_handler->Attach(this);
1417 AddMessageHandler(downloads_handler); 1418 AddMessageHandler(downloads_handler);
1418 downloads_handler->Init(); 1419 downloads_handler->Init();
1419 1420
1420 AddMessageHandler(new ShownSectionsHandler(this)); 1421 AddMessageHandler((new ShownSectionsHandler())->Attach(this));
1421 } 1422 }
1422 1423
1424 AddMessageHandler((new TemplateURLHandler())->Attach(this));
1425 AddMessageHandler((new MostVisitedHandler())->Attach(this));
1426 AddMessageHandler((new RecentlyBookmarkedHandler())->Attach(this));
1427 AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this));
1428 AddMessageHandler((new HistoryHandler())->Attach(this));
1429 AddMessageHandler((new MetricsHandler())->Attach(this));
1423 if (EnableWebResources()) 1430 if (EnableWebResources())
1424 AddMessageHandler(new TipsHandler(this)); 1431 AddMessageHandler((new TipsHandler())->Attach(this));
1425 1432
1426 AddMessageHandler(new TemplateURLHandler(this));
1427 AddMessageHandler(new MostVisitedHandler(this));
1428 AddMessageHandler(new RecentlyBookmarkedHandler(this));
1429 AddMessageHandler(new RecentlyClosedTabsHandler(this));
1430 AddMessageHandler(new HistoryHandler(this));
1431 AddMessageHandler(new MetricsHandler(this));
1432 #ifdef CHROME_PERSONALIZATION 1433 #ifdef CHROME_PERSONALIZATION
1433 if (!Personalization::IsP13NDisabled(GetProfile())) { 1434 if (!Personalization::IsP13NDisabled(GetProfile())) {
1434 AddMessageHandler(Personalization::CreateNewTabPageHandler(this)); 1435 AddMessageHandler(Personalization::CreateNewTabPageHandler(this));
1435 } 1436 }
1436 #endif 1437 #endif
1437 1438
1438 // In testing mode there may not be an I/O thread. 1439 // In testing mode there may not be an I/O thread.
1439 if (g_browser_process->io_thread()) { 1440 if (g_browser_process->io_thread()) {
1440 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, 1441 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
1441 NewRunnableMethod(&chrome_url_data_manager, 1442 NewRunnableMethod(&chrome_url_data_manager,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 bool NewTabUI::EnableNewNewTabPage() { 1489 bool NewTabUI::EnableNewNewTabPage() {
1489 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 1490 const CommandLine* command_line = CommandLine::ForCurrentProcess();
1490 return command_line->HasSwitch(switches::kNewNewTabPage); 1491 return command_line->HasSwitch(switches::kNewNewTabPage);
1491 } 1492 }
1492 1493
1493 bool NewTabUI::EnableWebResources() { 1494 bool NewTabUI::EnableWebResources() {
1494 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 1495 const CommandLine* command_line = CommandLine::ForCurrentProcess();
1495 return command_line->HasSwitch(switches::kWebResources); 1496 return command_line->HasSwitch(switches::kWebResources);
1496 } 1497 }
1497 1498
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/html_dialog_ui.cc ('k') | chrome/browser/dom_ui/shown_sections_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698