diff options
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/dom_ui.cc | 5 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui.h | 11 | ||||
-rw-r--r-- | chrome/browser/dom_ui/downloads_dom_handler.cc | 42 | ||||
-rw-r--r-- | chrome/browser/dom_ui/downloads_dom_handler.h | 5 | ||||
-rw-r--r-- | chrome/browser/dom_ui/downloads_ui.cc | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/history_ui.cc | 40 | ||||
-rw-r--r-- | chrome/browser/dom_ui/history_ui.h | 6 | ||||
-rw-r--r-- | chrome/browser/dom_ui/html_dialog_ui.cc | 11 | ||||
-rw-r--r-- | chrome/browser/dom_ui/html_dialog_ui.h | 9 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 174 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler.cc | 8 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler.h | 8 | ||||
-rw-r--r-- | chrome/browser/dom_ui/tips_handler.cc | 13 | ||||
-rw-r--r-- | chrome/browser/dom_ui/tips_handler.h | 10 |
14 files changed, 194 insertions, 152 deletions
diff --git a/chrome/browser/dom_ui/dom_ui.cc b/chrome/browser/dom_ui/dom_ui.cc index 5e92c57..3a7b221 100644 --- a/chrome/browser/dom_ui/dom_ui.cc +++ b/chrome/browser/dom_ui/dom_ui.cc @@ -110,7 +110,10 @@ void DOMUI::ExecuteJavascript(const std::wstring& javascript) { /////////////////////////////////////////////////////////////////////////////// // DOMMessageHandler -DOMMessageHandler::DOMMessageHandler(DOMUI *dom_ui) : dom_ui_(dom_ui) { +DOMMessageHandler* DOMMessageHandler::Attach(DOMUI* dom_ui) { + dom_ui_ = dom_ui; + RegisterMessages(); + return this; } // DOMMessageHandler, protected: ---------------------------------------------- diff --git a/chrome/browser/dom_ui/dom_ui.h b/chrome/browser/dom_ui/dom_ui.h index 553ab28..f7bb0e7 100644 --- a/chrome/browser/dom_ui/dom_ui.h +++ b/chrome/browser/dom_ui/dom_ui.h @@ -129,9 +129,13 @@ class DOMUI { // host is destroyed. class DOMMessageHandler { public: - explicit DOMMessageHandler(DOMUI* dom_ui); + DOMMessageHandler() : dom_ui_(NULL) {} virtual ~DOMMessageHandler() {}; + // Attaches |this| to |dom_ui| in order to handle messages from it. Declared + // virtual so that subclasses can do special init work as soon as the dom_ui + // is provided. Returns |this| for convenience. + virtual DOMMessageHandler* Attach(DOMUI* dom_ui); protected: // Adds "url" and "title" keys on incoming dictionary, setting title // as the url as a fallback on empty title. @@ -139,13 +143,16 @@ class DOMMessageHandler { std::wstring title, const GURL& gurl); + // This is where subclasses specify which messages they'd like to handle. + virtual void RegisterMessages() = 0; + // Extract an integer value from a Value. bool ExtractIntegerValue(const Value* value, int* out_int); // Extract a string value from a Value. std::wstring ExtractStringValue(const Value* value); - DOMUI* const dom_ui_; + DOMUI* dom_ui_; private: DISALLOW_COPY_AND_ASSIGN(DOMMessageHandler); diff --git a/chrome/browser/dom_ui/downloads_dom_handler.cc b/chrome/browser/dom_ui/downloads_dom_handler.cc index b27a520..66ee916 100644 --- a/chrome/browser/dom_ui/downloads_dom_handler.cc +++ b/chrome/browser/dom_ui/downloads_dom_handler.cc @@ -47,10 +47,28 @@ class DownloadItemSorter : public std::binary_function<DownloadItem*, } // namespace -DownloadsDOMHandler::DownloadsDOMHandler(DOMUI* dom_ui, DownloadManager* dlm) - : DOMMessageHandler(dom_ui), - search_text_(), +DownloadsDOMHandler::DownloadsDOMHandler(DownloadManager* dlm) + : search_text_(), download_manager_(dlm) { + // Create our fileicon data source. + g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, + NewRunnableMethod(&chrome_url_data_manager, + &ChromeURLDataManager::AddDataSource, + new FileIconSource())); +} + +DownloadsDOMHandler::~DownloadsDOMHandler() { + ClearDownloadItems(); + download_manager_->RemoveObserver(this); +} + +// DownloadsDOMHandler, public: ----------------------------------------------- + +void DownloadsDOMHandler::Init() { + download_manager_->AddObserver(this); +} + +void DownloadsDOMHandler::RegisterMessages() { dom_ui_->RegisterMessageCallback("getDownloads", NewCallback(this, &DownloadsDOMHandler::HandleGetDownloads)); dom_ui_->RegisterMessageCallback("openFile", @@ -73,24 +91,6 @@ DownloadsDOMHandler::DownloadsDOMHandler(DOMUI* dom_ui, DownloadManager* dlm) NewCallback(this, &DownloadsDOMHandler::HandleCancel)); dom_ui_->RegisterMessageCallback("clearAll", NewCallback(this, &DownloadsDOMHandler::HandleClearAll)); - - - // Create our fileicon data source. - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(&chrome_url_data_manager, - &ChromeURLDataManager::AddDataSource, - new FileIconSource())); -} - -DownloadsDOMHandler::~DownloadsDOMHandler() { - ClearDownloadItems(); - download_manager_->RemoveObserver(this); -} - -// DownloadsDOMHandler, public: ----------------------------------------------- - -void DownloadsDOMHandler::Init() { - download_manager_->AddObserver(this); } void DownloadsDOMHandler::OnDownloadUpdated(DownloadItem* download) { diff --git a/chrome/browser/dom_ui/downloads_dom_handler.h b/chrome/browser/dom_ui/downloads_dom_handler.h index 729960c..a0158c4 100644 --- a/chrome/browser/dom_ui/downloads_dom_handler.h +++ b/chrome/browser/dom_ui/downloads_dom_handler.h @@ -19,11 +19,14 @@ class DownloadsDOMHandler : public DOMMessageHandler, public DownloadManager::Observer, public DownloadItem::Observer { public: - explicit DownloadsDOMHandler(DOMUI* dom_ui, DownloadManager* dlm); + explicit DownloadsDOMHandler(DownloadManager* dlm); virtual ~DownloadsDOMHandler(); void Init(); + // DOMMessageHandler implementation. + virtual void RegisterMessages(); + // DownloadItem::Observer interface virtual void OnDownloadUpdated(DownloadItem* download); virtual void OnDownloadOpened(DownloadItem* download) { } diff --git a/chrome/browser/dom_ui/downloads_ui.cc b/chrome/browser/dom_ui/downloads_ui.cc index 6840b00..df1c21c 100644 --- a/chrome/browser/dom_ui/downloads_ui.cc +++ b/chrome/browser/dom_ui/downloads_ui.cc @@ -121,9 +121,9 @@ DownloadsUI::DownloadsUI(TabContents* contents) : DOMUI(contents) { DownloadManager* dlm = GetProfile()->GetOriginalProfile()-> GetDownloadManager(); - DownloadsDOMHandler* handler = new DownloadsDOMHandler(this, dlm); + DownloadsDOMHandler* handler = new DownloadsDOMHandler(dlm); AddMessageHandler(handler); - handler->Init(); + handler->Attach(this); DownloadsUIHTMLSource* html_source = new DownloadsUIHTMLSource(); diff --git a/chrome/browser/dom_ui/history_ui.cc b/chrome/browser/dom_ui/history_ui.cc index b40b6ff..1e0bd75 100644 --- a/chrome/browser/dom_ui/history_ui.cc +++ b/chrome/browser/dom_ui/history_ui.cc @@ -96,32 +96,38 @@ void HistoryUIHTMLSource::StartDataRequest(const std::string& path, // HistoryHandler // //////////////////////////////////////////////////////////////////////////////// -BrowsingHistoryHandler::BrowsingHistoryHandler(DOMUI* dom_ui) - : DOMMessageHandler(dom_ui), - search_text_(), +BrowsingHistoryHandler::BrowsingHistoryHandler() + : search_text_(), remover_(NULL) { - dom_ui_->RegisterMessageCallback("getHistory", - NewCallback(this, &BrowsingHistoryHandler::HandleGetHistory)); - dom_ui_->RegisterMessageCallback("searchHistory", - NewCallback(this, &BrowsingHistoryHandler::HandleSearchHistory)); - dom_ui_->RegisterMessageCallback("deleteDay", - NewCallback(this, &BrowsingHistoryHandler::HandleDeleteDay)); + +} +BrowsingHistoryHandler::~BrowsingHistoryHandler() { + cancelable_consumer_.CancelAllRequests(); + if (remover_.get()) + remover_->RemoveObserver(this); +} + +DOMMessageHandler* BrowsingHistoryHandler::Attach(DOMUI* dom_ui) { // Create our favicon data source. g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(&chrome_url_data_manager, - &ChromeURLDataManager::AddDataSource, - new DOMUIFavIconSource(dom_ui_->GetProfile()))); + &ChromeURLDataManager::AddDataSource, + new DOMUIFavIconSource(dom_ui->GetProfile()))); // Get notifications when history is cleared. registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, - Source<Profile>(dom_ui_->GetProfile()->GetOriginalProfile())); + Source<Profile>(dom_ui->GetProfile()->GetOriginalProfile())); + return DOMMessageHandler::Attach(dom_ui); } -BrowsingHistoryHandler::~BrowsingHistoryHandler() { - cancelable_consumer_.CancelAllRequests(); - if (remover_.get()) - remover_->RemoveObserver(this); +void BrowsingHistoryHandler::RegisterMessages() { + dom_ui_->RegisterMessageCallback("getHistory", + NewCallback(this, &BrowsingHistoryHandler::HandleGetHistory)); + dom_ui_->RegisterMessageCallback("searchHistory", + NewCallback(this, &BrowsingHistoryHandler::HandleSearchHistory)); + dom_ui_->RegisterMessageCallback("deleteDay", + NewCallback(this, &BrowsingHistoryHandler::HandleDeleteDay)); } void BrowsingHistoryHandler::HandleGetHistory(const Value* value) { @@ -356,7 +362,7 @@ void BrowsingHistoryHandler::Observe(NotificationType type, //////////////////////////////////////////////////////////////////////////////// HistoryUI::HistoryUI(TabContents* contents) : DOMUI(contents) { - AddMessageHandler(new BrowsingHistoryHandler(this)); + AddMessageHandler((new BrowsingHistoryHandler())->Attach(this)); HistoryUIHTMLSource* html_source = new HistoryUIHTMLSource(); diff --git a/chrome/browser/dom_ui/history_ui.h b/chrome/browser/dom_ui/history_ui.h index f44e033..0a47120 100644 --- a/chrome/browser/dom_ui/history_ui.h +++ b/chrome/browser/dom_ui/history_ui.h @@ -35,9 +35,13 @@ class BrowsingHistoryHandler : public DOMMessageHandler, public NotificationObserver, public BrowsingDataRemover::Observer { public: - explicit BrowsingHistoryHandler(DOMUI* dom_ui_); + BrowsingHistoryHandler(); virtual ~BrowsingHistoryHandler(); + // DOMMessageHandler implementation. + virtual DOMMessageHandler* Attach(DOMUI* dom_ui); + virtual void RegisterMessages(); + // Callback for the "getHistory" message. void HandleGetHistory(const Value* value); diff --git a/chrome/browser/dom_ui/html_dialog_ui.cc b/chrome/browser/dom_ui/html_dialog_ui.cc index 060625d..4f7995d 100644 --- a/chrome/browser/dom_ui/html_dialog_ui.cc +++ b/chrome/browser/dom_ui/html_dialog_ui.cc @@ -61,11 +61,20 @@ void HtmlDialogUI::RenderViewCreated(RenderViewHost* render_view_host) { // Pass the arguments to the renderer supplied by the delegate. std::string dialog_args; + std::vector<DOMMessageHandler*> handlers; HtmlDialogUIDelegate** delegate = GetPropertyAccessor().GetProperty( tab_contents()->property_bag()); - if (delegate) + if (delegate) { dialog_args = (*delegate)->GetDialogArgs(); + (*delegate)->GetDOMMessageHandlers(&handlers); + } + render_view_host->SetDOMUIProperty("dialogArguments", dialog_args); + for (std::vector<DOMMessageHandler*>::iterator it = handlers.begin(); + it != handlers.end(); ++it) { + (*it)->Attach(this); + AddMessageHandler(*it); + } } void HtmlDialogUI::OnDialogClosed(const Value* content) { diff --git a/chrome/browser/dom_ui/html_dialog_ui.h b/chrome/browser/dom_ui/html_dialog_ui.h index 76240cd..fce8f7c 100644 --- a/chrome/browser/dom_ui/html_dialog_ui.h +++ b/chrome/browser/dom_ui/html_dialog_ui.h @@ -5,6 +5,8 @@ #ifndef CHROME_BROWSER_DOM_UI_HTML_DIALOG_UI_H_ #define CHROME_BROWSER_DOM_UI_HTML_DIALOG_UI_H_ +#include <vector> + #include "chrome/browser/dom_ui/dom_ui.h" #include "chrome/common/property_bag.h" #include "googleurl/src/gurl.h" @@ -25,6 +27,13 @@ class HtmlDialogUIDelegate { // Get the HTML file path for the content to load in the dialog. virtual GURL GetDialogContentURL() const = 0; + // Get DOMMessageHandler objects to handle messages from the HTML/JS page. + // The handlers are used to send and receive messages from the page while it + // is still open. Ownership of each handler is taken over by the DOMUI + // hosting the page. + virtual void GetDOMMessageHandlers( + std::vector<DOMMessageHandler*>* handlers) const = 0; + // Get the size of the dialog. virtual void GetDialogSize(gfx::Size* size) const = 0; diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index f6af1ad..71779a8 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -458,8 +458,12 @@ void IncognitoTabHTMLSource::StartDataRequest(const std::string& path, class MostVisitedHandler : public DOMMessageHandler, public NotificationObserver { public: - explicit MostVisitedHandler(DOMUI* dom_ui); - virtual ~MostVisitedHandler(); + MostVisitedHandler() : url_blacklist_(NULL), pinned_urls_(NULL) {} + virtual ~MostVisitedHandler() { } + + // DOMMessageHandler override and implementation. + virtual DOMMessageHandler* Attach(DOMUI* dom_ui); + virtual void RegisterMessages(); // Callback for the "getMostVisited" message. void HandleGetMostVisited(const Value* value); @@ -533,33 +537,11 @@ class MostVisitedHandler : public DOMMessageHandler, DISALLOW_COPY_AND_ASSIGN(MostVisitedHandler); }; -MostVisitedHandler::MostVisitedHandler(DOMUI* dom_ui) - : DOMMessageHandler(dom_ui) { - // Register ourselves as the handler for the "mostvisited" message from - // Javascript. - dom_ui_->RegisterMessageCallback("getMostVisited", - NewCallback(this, &MostVisitedHandler::HandleGetMostVisited)); - - // Register ourselves for any most-visited item blacklisting. - dom_ui_->RegisterMessageCallback("blacklistURLFromMostVisited", - NewCallback(this, &MostVisitedHandler::HandleBlacklistURL)); - dom_ui_->RegisterMessageCallback("removeURLsFromMostVisitedBlacklist", - NewCallback(this, &MostVisitedHandler::HandleRemoveURLsFromBlacklist)); - dom_ui_->RegisterMessageCallback("clearMostVisitedURLsBlacklist", - NewCallback(this, &MostVisitedHandler::HandleClearBlacklist)); - - url_blacklist_ = dom_ui_->GetProfile()->GetPrefs()-> +DOMMessageHandler* MostVisitedHandler::Attach(DOMUI* dom_ui) { + url_blacklist_ = dom_ui->GetProfile()->GetPrefs()-> GetMutableDictionary(prefs::kNTPMostVisitedURLsBlacklist); - - // Register ourself for pinned URL messages. - dom_ui->RegisterMessageCallback("addPinnedURL", - NewCallback(this, &MostVisitedHandler::HandleAddPinnedURL)); - dom_ui->RegisterMessageCallback("removePinnedURL", - NewCallback(this, &MostVisitedHandler::HandleRemovePinnedURL)); - - pinned_urls_ = dom_ui_->GetProfile()->GetPrefs()-> - GetMutableDictionary(prefs::kNTPMostVisitedPinnedURLs); - + pinned_urls_ = dom_ui->GetProfile()->GetPrefs()-> + GetMutableDictionary(prefs::kNTPMostVisitedPinnedURLs); // Set up our sources for thumbnail and favicon data. Since we may be in // testing mode with no I/O thread, only add our handler when an I/O thread // exists. Ownership is passed to the ChromeURLDataManager. @@ -576,10 +558,30 @@ MostVisitedHandler::MostVisitedHandler(DOMUI* dom_ui) // Get notifications when history is cleared. registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, - Source<Profile>(dom_ui_->GetProfile())); + Source<Profile>(dom_ui->GetProfile())); + + return DOMMessageHandler::Attach(dom_ui); } -MostVisitedHandler::~MostVisitedHandler() { +void MostVisitedHandler::RegisterMessages() { + // Register ourselves as the handler for the "mostvisited" message from + // Javascript. + dom_ui_->RegisterMessageCallback("getMostVisited", + NewCallback(this, &MostVisitedHandler::HandleGetMostVisited)); + + // Register ourselves for any most-visited item blacklisting. + dom_ui_->RegisterMessageCallback("blacklistURLFromMostVisited", + NewCallback(this, &MostVisitedHandler::HandleBlacklistURL)); + dom_ui_->RegisterMessageCallback("removeURLsFromMostVisitedBlacklist", + NewCallback(this, &MostVisitedHandler::HandleRemoveURLsFromBlacklist)); + dom_ui_->RegisterMessageCallback("clearMostVisitedURLsBlacklist", + NewCallback(this, &MostVisitedHandler::HandleClearBlacklist)); + + // Register ourself for pinned URL messages. + dom_ui_->RegisterMessageCallback("addPinnedURL", + NewCallback(this, &MostVisitedHandler::HandleAddPinnedURL)); + dom_ui_->RegisterMessageCallback("removePinnedURL", + NewCallback(this, &MostVisitedHandler::HandleRemovePinnedURL)); } void MostVisitedHandler::HandleGetMostVisited(const Value* value) { @@ -828,9 +830,12 @@ void MostVisitedHandler::RegisterUserPrefs(PrefService* prefs) { class TemplateURLHandler : public DOMMessageHandler, public TemplateURLModelObserver { public: - explicit TemplateURLHandler(DOMUI* dom_ui); + TemplateURLHandler() : DOMMessageHandler(), template_url_model_(NULL) {} virtual ~TemplateURLHandler(); + // DOMMessageHandler implementation. + virtual void RegisterMessages(); + // Callback for the "getMostSearched" message, sent when the page requests // the list of available searches. void HandleGetMostSearched(const Value* content); @@ -843,27 +848,23 @@ class TemplateURLHandler : public DOMMessageHandler, virtual void OnTemplateURLModelChanged(); private: - DOMUI* dom_ui_; TemplateURLModel* template_url_model_; // Owned by profile. DISALLOW_COPY_AND_ASSIGN(TemplateURLHandler); }; -TemplateURLHandler::TemplateURLHandler(DOMUI* dom_ui) - : DOMMessageHandler(dom_ui), - dom_ui_(dom_ui), - template_url_model_(NULL) { - dom_ui->RegisterMessageCallback("getMostSearched", - NewCallback(this, &TemplateURLHandler::HandleGetMostSearched)); - dom_ui->RegisterMessageCallback("doSearch", - NewCallback(this, &TemplateURLHandler::HandleDoSearch)); -} - TemplateURLHandler::~TemplateURLHandler() { if (template_url_model_) template_url_model_->RemoveObserver(this); } +void TemplateURLHandler::RegisterMessages() { + dom_ui_->RegisterMessageCallback("getMostSearched", + NewCallback(this, &TemplateURLHandler::HandleGetMostSearched)); + dom_ui_->RegisterMessageCallback("doSearch", + NewCallback(this, &TemplateURLHandler::HandleDoSearch)); +} + void TemplateURLHandler::HandleGetMostSearched(const Value* content) { // The page Javascript has requested the list of keyword searches. // Start loading them from the template URL backend. @@ -989,8 +990,11 @@ void TemplateURLHandler::OnTemplateURLModelChanged() { class RecentlyBookmarkedHandler : public DOMMessageHandler, public BookmarkModelObserver { public: - explicit RecentlyBookmarkedHandler(DOMUI* dom_ui); - ~RecentlyBookmarkedHandler(); + RecentlyBookmarkedHandler() : model_(NULL) {} + virtual ~RecentlyBookmarkedHandler(); + + // DOMMessageHandler implementation. + virtual void RegisterMessages(); // Callback which navigates to the bookmarks page. void HandleShowBookmarkPage(const Value*); @@ -1024,27 +1028,23 @@ class RecentlyBookmarkedHandler : public DOMMessageHandler, virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, const BookmarkNode* node) {} - DOMUI* dom_ui_; // The model we're getting bookmarks from. The model is owned by the Profile. BookmarkModel* model_; DISALLOW_COPY_AND_ASSIGN(RecentlyBookmarkedHandler); }; -RecentlyBookmarkedHandler::RecentlyBookmarkedHandler(DOMUI* dom_ui) - : DOMMessageHandler(dom_ui), - dom_ui_(dom_ui), - model_(NULL) { - dom_ui->RegisterMessageCallback("getRecentlyBookmarked", - NewCallback(this, - &RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked)); -} - RecentlyBookmarkedHandler::~RecentlyBookmarkedHandler() { if (model_) model_->RemoveObserver(this); } +void RecentlyBookmarkedHandler::RegisterMessages() { + dom_ui_->RegisterMessageCallback("getRecentlyBookmarked", + NewCallback(this, + &RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked)); +} + void RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked(const Value*) { if (!model_) { model_ = dom_ui_->GetProfile()->GetBookmarkModel(); @@ -1100,9 +1100,12 @@ void RecentlyBookmarkedHandler::BookmarkNodeChanged(BookmarkModel* model, class RecentlyClosedTabsHandler : public DOMMessageHandler, public TabRestoreService::Observer { public: - explicit RecentlyClosedTabsHandler(DOMUI* dom_ui); + RecentlyClosedTabsHandler() : tab_restore_service_(NULL) {} virtual ~RecentlyClosedTabsHandler(); + // DOMMessageHandler implementation. + virtual void RegisterMessages(); + // Callback for the "reopenTab" message. Rewrites the history of the // currently displayed tab to be the one in TabRestoreService with a // history of a session passed in through the content pointer. @@ -1131,22 +1134,17 @@ class RecentlyClosedTabsHandler : public DOMMessageHandler, bool WindowToValue(const TabRestoreService::Window& window, DictionaryValue* dictionary); - DOMUI* dom_ui_; - // TabRestoreService that we are observing. TabRestoreService* tab_restore_service_; DISALLOW_COPY_AND_ASSIGN(RecentlyClosedTabsHandler); }; -RecentlyClosedTabsHandler::RecentlyClosedTabsHandler(DOMUI* dom_ui) - : DOMMessageHandler(dom_ui), - dom_ui_(dom_ui), - tab_restore_service_(NULL) { - dom_ui->RegisterMessageCallback("getRecentlyClosedTabs", +void RecentlyClosedTabsHandler::RegisterMessages() { + dom_ui_->RegisterMessageCallback("getRecentlyClosedTabs", NewCallback(this, &RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs)); - dom_ui->RegisterMessageCallback("reopenTab", + dom_ui_->RegisterMessageCallback("reopenTab", NewCallback(this, &RecentlyClosedTabsHandler::HandleReopenTab)); } @@ -1286,21 +1284,22 @@ bool RecentlyClosedTabsHandler::WindowToValue( class HistoryHandler : public DOMMessageHandler { public: - explicit HistoryHandler(DOMUI* dom_ui); + HistoryHandler() {} + virtual ~HistoryHandler() {} + + // DOMMessageHandler implementation. + virtual void RegisterMessages(); // Callback which navigates to the history page and performs a search. void HandleSearchHistoryPage(const Value* content); private: - DOMUI* dom_ui_; DISALLOW_COPY_AND_ASSIGN(HistoryHandler); }; -HistoryHandler::HistoryHandler(DOMUI* dom_ui) - : DOMMessageHandler(dom_ui), - dom_ui_(dom_ui) { - dom_ui->RegisterMessageCallback("searchHistoryPage", +void HistoryHandler::RegisterMessages() { + dom_ui_->RegisterMessageCallback("searchHistoryPage", NewCallback(this, &HistoryHandler::HandleSearchHistoryPage)); } @@ -1336,21 +1335,22 @@ void HistoryHandler::HandleSearchHistoryPage(const Value* content) { // information (treat it as RecordComputedMetrics) class MetricsHandler : public DOMMessageHandler { public: - explicit MetricsHandler(DOMUI* dom_ui); - + MetricsHandler() {} + virtual ~MetricsHandler() {} + + // DOMMessageHandler implementation. + virtual void RegisterMessages(); + // Callback which records a user action. void HandleMetrics(const Value* content); private: - DOMUI* dom_ui_; DISALLOW_COPY_AND_ASSIGN(MetricsHandler); }; -MetricsHandler::MetricsHandler(DOMUI* dom_ui) - : DOMMessageHandler(dom_ui), - dom_ui_(dom_ui) { - dom_ui->RegisterMessageCallback("metrics", +void MetricsHandler::RegisterMessages() { + dom_ui_->RegisterMessageCallback("metrics", NewCallback(this, &MetricsHandler::HandleMetrics)); } @@ -1409,26 +1409,26 @@ NewTabUI::NewTabUI(TabContents* contents) &ChromeURLDataManager::AddDataSource, html_source)); } else { - if (EnableNewNewTabPage()) { DownloadManager* dlm = GetProfile()->GetDownloadManager(); DownloadsDOMHandler* downloads_handler = - new DownloadsDOMHandler(this, dlm); + new DownloadsDOMHandler(dlm); + downloads_handler->Attach(this); AddMessageHandler(downloads_handler); downloads_handler->Init(); - AddMessageHandler(new ShownSectionsHandler(this)); + AddMessageHandler((new ShownSectionsHandler())->Attach(this)); } + AddMessageHandler((new TemplateURLHandler())->Attach(this)); + AddMessageHandler((new MostVisitedHandler())->Attach(this)); + AddMessageHandler((new RecentlyBookmarkedHandler())->Attach(this)); + AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this)); + AddMessageHandler((new HistoryHandler())->Attach(this)); + AddMessageHandler((new MetricsHandler())->Attach(this)); if (EnableWebResources()) - AddMessageHandler(new TipsHandler(this)); - - AddMessageHandler(new TemplateURLHandler(this)); - AddMessageHandler(new MostVisitedHandler(this)); - AddMessageHandler(new RecentlyBookmarkedHandler(this)); - AddMessageHandler(new RecentlyClosedTabsHandler(this)); - AddMessageHandler(new HistoryHandler(this)); - AddMessageHandler(new MetricsHandler(this)); + AddMessageHandler((new TipsHandler())->Attach(this)); + #ifdef CHROME_PERSONALIZATION if (!Personalization::IsP13NDisabled(GetProfile())) { AddMessageHandler(Personalization::CreateNewTabPageHandler(this)); diff --git a/chrome/browser/dom_ui/shown_sections_handler.cc b/chrome/browser/dom_ui/shown_sections_handler.cc index 22597cb..353dae9 100644 --- a/chrome/browser/dom_ui/shown_sections_handler.cc +++ b/chrome/browser/dom_ui/shown_sections_handler.cc @@ -9,12 +9,10 @@ #include "chrome/browser/profile.h" #include "chrome/common/pref_names.h" -ShownSectionsHandler::ShownSectionsHandler(DOMUI* dom_ui) - : DOMMessageHandler(dom_ui), - dom_ui_(dom_ui) { - dom_ui->RegisterMessageCallback("getShownSections", +void ShownSectionsHandler::RegisterMessages() { + dom_ui_->RegisterMessageCallback("getShownSections", NewCallback(this, &ShownSectionsHandler::HandleGetShownSections)); - dom_ui->RegisterMessageCallback("setShownSections", + dom_ui_->RegisterMessageCallback("setShownSections", NewCallback(this, &ShownSectionsHandler::HandleSetShownSections)); } diff --git a/chrome/browser/dom_ui/shown_sections_handler.h b/chrome/browser/dom_ui/shown_sections_handler.h index 798a14f..70a7a50 100644 --- a/chrome/browser/dom_ui/shown_sections_handler.h +++ b/chrome/browser/dom_ui/shown_sections_handler.h @@ -21,7 +21,11 @@ enum Section { class ShownSectionsHandler : public DOMMessageHandler { public: - explicit ShownSectionsHandler(DOMUI* dom_ui); + ShownSectionsHandler() {} + virtual ~ShownSectionsHandler() {} + + // DOMMessageHandler implementation. + virtual void RegisterMessages(); // Callback for "getShownSections" message. void HandleGetShownSections(const Value* value); @@ -32,8 +36,6 @@ class ShownSectionsHandler : public DOMMessageHandler { static void RegisterUserPrefs(PrefService* prefs); private: - DOMUI* dom_ui_; - DISALLOW_COPY_AND_ASSIGN(ShownSectionsHandler); }; diff --git a/chrome/browser/dom_ui/tips_handler.cc b/chrome/browser/dom_ui/tips_handler.cc index 3d26945..f935abd 100644 --- a/chrome/browser/dom_ui/tips_handler.cc +++ b/chrome/browser/dom_ui/tips_handler.cc @@ -21,14 +21,15 @@ namespace { L"Tips and recommendations to help you discover interesting websites."; } -TipsHandler::TipsHandler(DOMUI* dom_ui) - : DOMMessageHandler(dom_ui), - dom_ui_(dom_ui) { - dom_ui->RegisterMessageCallback("getTips", - NewCallback(this, &TipsHandler::HandleGetTips)); - +DOMMessageHandler* TipsHandler::Attach(DOMUI* dom_ui) { tips_cache_ = dom_ui_->GetProfile()->GetPrefs()-> GetDictionary(prefs::kNTPTipsCache); + return DOMMessageHandler::Attach(dom_ui); +} + +void TipsHandler::RegisterMessages() { + dom_ui_->RegisterMessageCallback("getTips", + NewCallback(this, &TipsHandler::HandleGetTips)); } void TipsHandler::HandleGetTips(const Value* content) { diff --git a/chrome/browser/dom_ui/tips_handler.h b/chrome/browser/dom_ui/tips_handler.h index 7847ba6..b6d5ccc 100644 --- a/chrome/browser/dom_ui/tips_handler.h +++ b/chrome/browser/dom_ui/tips_handler.h @@ -28,9 +28,12 @@ class Value; class TipsHandler : public DOMMessageHandler { public: - explicit TipsHandler(DOMUI* dom_ui); + TipsHandler() : tips_cache_(NULL) {} + virtual ~TipsHandler() {} - TipsHandler(); + // DOMMessageHandler implementation and overrides. + virtual DOMMessageHandler* Attach(DOMUI* dom_ui); + virtual void RegisterMessages(); // Callback which pulls tips data from the preferences. void HandleGetTips(const Value* content); @@ -42,9 +45,6 @@ class TipsHandler : public DOMMessageHandler { // Make sure the string we are pushing to the NTP is a valid URL. bool IsValidURL(const std::wstring& url_string); - // So we can push data out to the page that has called this handler. - DOMUI* dom_ui_; - // Filled with data from cache in preferences. const DictionaryValue* tips_cache_; |