summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
authorarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-20 22:47:33 +0000
committerarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-20 22:47:33 +0000
commit655aa8d8075c12a8846bedfb080ab71f4231aaa0 (patch)
tree18cd8a8a5bf67eed38b738fcdb28bb950286b0aa /chrome/browser/dom_ui
parent8f810bfb73db594e4b1da71a75e521ae37ecdfe3 (diff)
downloadchromium_src-655aa8d8075c12a8846bedfb080ab71f4231aaa0.zip
chromium_src-655aa8d8075c12a8846bedfb080ab71f4231aaa0.tar.gz
chromium_src-655aa8d8075c12a8846bedfb080ab71f4231aaa0.tar.bz2
Remove the unused handlers as well
BUG=None TEST=None Review URL: http://codereview.chromium.org/292001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29579 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.cc322
1 files changed, 1 insertions, 321 deletions
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc
index a432574..2a418c9 100644
--- a/chrome/browser/dom_ui/new_tab_ui.cc
+++ b/chrome/browser/dom_ui/new_tab_ui.cc
@@ -16,12 +16,10 @@
#include "base/file_util.h"
#include "base/histogram.h"
#include "base/string_piece.h"
-#include "chrome/browser/bookmarks/bookmark_model.h"
-#include "chrome/browser/bookmarks/bookmark_utils.h"
+#include "base/thread.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/dom_ui/dom_ui_theme_source.h"
-#include "chrome/browser/dom_ui/history_ui.h"
#include "chrome/browser/dom_ui/most_visited_handler.h"
#include "chrome/browser/dom_ui/new_tab_page_sync_handler.h"
#include "chrome/browser/dom_ui/shown_sections_handler.h"
@@ -29,10 +27,8 @@
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_view_host.h"
-#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/sessions/session_types.h"
#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/sessions/tab_restore_service.h"
#include "chrome/browser/user_data_manager.h"
#include "chrome/common/chrome_switches.h"
@@ -199,278 +195,6 @@ void IncognitoTabHTMLSource::InitFullHTML() {
}
///////////////////////////////////////////////////////////////////////////////
-// TemplateURLHandler
-
-// The handler for Javascript messages related to the "common searches" view.
-class TemplateURLHandler : public DOMMessageHandler,
- public TemplateURLModelObserver {
- public:
- 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);
- // Callback for the "doSearch" message, sent when the user wants to
- // run a search. Content of the message is an array containing
- // [<the search keyword>, <the search term>].
- void HandleDoSearch(const Value* content);
-
- // TemplateURLModelObserver implementation.
- virtual void OnTemplateURLModelChanged();
-
- private:
- TemplateURLModel* template_url_model_; // Owned by profile.
-
- DISALLOW_COPY_AND_ASSIGN(TemplateURLHandler);
-};
-
-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.
- if (!template_url_model_) {
- template_url_model_ = dom_ui_->GetProfile()->GetTemplateURLModel();
- template_url_model_->AddObserver(this);
- }
- if (template_url_model_->loaded()) {
- OnTemplateURLModelChanged();
- } else {
- template_url_model_->Load();
- }
-}
-
-// A helper function for sorting TemplateURLs where the most used ones show up
-// first.
-static bool TemplateURLSortByUsage(const TemplateURL* a,
- const TemplateURL* b) {
- return a->usage_count() > b->usage_count();
-}
-
-void TemplateURLHandler::HandleDoSearch(const Value* content) {
- // Extract the parameters out of the input list.
- if (!content || !content->IsType(Value::TYPE_LIST)) {
- NOTREACHED();
- return;
- }
- const ListValue* args = static_cast<const ListValue*>(content);
- if (args->GetSize() != 2) {
- NOTREACHED();
- return;
- }
- std::wstring keyword, search;
- Value* value = NULL;
- if (!args->Get(0, &value) || !value->GetAsString(&keyword)) {
- NOTREACHED();
- return;
- }
- if (!args->Get(1, &value) || !value->GetAsString(&search)) {
- NOTREACHED();
- return;
- }
-
- // Combine the keyword and search into a URL.
- const TemplateURL* template_url =
- template_url_model_->GetTemplateURLForKeyword(keyword);
- if (!template_url) {
- // The keyword seems to have changed out from under us.
- // Not an error, but nothing we can do...
- return;
- }
- const TemplateURLRef* url_ref = template_url->url();
- if (!url_ref || !url_ref->SupportsReplacement()) {
- NOTREACHED();
- return;
- }
- GURL url = GURL(WideToUTF8(url_ref->ReplaceSearchTerms(*template_url, search,
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())));
-
- if (url.is_valid()) {
- // Record the user action
- std::vector<const TemplateURL*> urls =
- template_url_model_->GetTemplateURLs();
- sort(urls.begin(), urls.end(), TemplateURLSortByUsage);
- ListValue urls_value;
- int item_number = 0;
- for (size_t i = 0;
- i < std::min<size_t>(urls.size(), kSearchURLs); ++i) {
- if (urls[i]->usage_count() == 0)
- break; // The remainder would be no good.
-
- const TemplateURLRef* urlref = urls[i]->url();
- if (!urlref)
- continue;
-
- if (urls[i] == template_url) {
- UserMetrics::RecordComputedAction(
- StringPrintf(L"NTP_SearchURL%d", item_number),
- dom_ui_->GetProfile());
- break;
- }
-
- item_number++;
- }
-
- // Load the URL.
- dom_ui_->tab_contents()->OpenURL(url, GURL(), CURRENT_TAB,
- PageTransition::LINK);
- // We've been deleted.
- return;
- }
-}
-
-void TemplateURLHandler::OnTemplateURLModelChanged() {
- // We've loaded some template URLs. Send them to the page.
- std::vector<const TemplateURL*> urls = template_url_model_->GetTemplateURLs();
- sort(urls.begin(), urls.end(), TemplateURLSortByUsage);
- ListValue urls_value;
- for (size_t i = 0; i < std::min<size_t>(urls.size(), kSearchURLs); ++i) {
- if (urls[i]->usage_count() == 0)
- break; // urls is sorted by usage count; the remainder would be no good.
-
- const TemplateURLRef* urlref = urls[i]->url();
- if (!urlref)
- continue;
- DictionaryValue* entry_value = new DictionaryValue;
- entry_value->SetString(L"short_name", urls[i]->short_name());
- entry_value->SetString(L"keyword", urls[i]->keyword());
-
- const GURL& url = urls[i]->GetFavIconURL();
- if (url.is_valid())
- entry_value->SetString(L"favIconURL", UTF8ToWide(url.spec()));
-
- urls_value.Append(entry_value);
- }
- UMA_HISTOGRAM_COUNTS("NewTabPage.SearchURLs.Total", urls_value.GetSize());
- dom_ui_->CallJavascriptFunction(L"searchURLs", urls_value);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// RecentlyBookmarkedHandler
-
-class RecentlyBookmarkedHandler : public DOMMessageHandler,
- public BookmarkModelObserver {
- public:
- RecentlyBookmarkedHandler() : model_(NULL) {}
- virtual ~RecentlyBookmarkedHandler();
-
- // DOMMessageHandler implementation.
- virtual void RegisterMessages();
-
- // Callback which navigates to the bookmarks page.
- void HandleShowBookmarkPage(const Value*);
-
- // Callback for the "getRecentlyBookmarked" message.
- // It takes no arguments.
- void HandleGetRecentlyBookmarked(const Value*);
-
- private:
- void SendBookmarksToPage();
-
- // BookmarkModelObserver methods. These invoke SendBookmarksToPage.
- virtual void Loaded(BookmarkModel* model);
- virtual void BookmarkNodeAdded(BookmarkModel* model,
- const BookmarkNode* parent,
- int index);
- virtual void BookmarkNodeRemoved(BookmarkModel* model,
- const BookmarkNode* parent,
- int old_index,
- const BookmarkNode* node);
- virtual void BookmarkNodeChanged(BookmarkModel* model,
- const BookmarkNode* node);
-
- // These won't effect what is shown, so they do nothing.
- virtual void BookmarkNodeMoved(BookmarkModel* model,
- const BookmarkNode* old_parent,
- int old_index,
- const BookmarkNode* new_parent,
- int new_index) {}
- virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- const BookmarkNode* node) {}
- virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- const BookmarkNode* node) {}
-
- // The model we're getting bookmarks from. The model is owned by the Profile.
- BookmarkModel* model_;
-
- DISALLOW_COPY_AND_ASSIGN(RecentlyBookmarkedHandler);
-};
-
-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();
- model_->AddObserver(this);
- }
- // If the model is loaded, synchronously send the bookmarks down. Otherwise
- // when the model loads we'll send the bookmarks down.
- if (model_->IsLoaded())
- SendBookmarksToPage();
-}
-
-void RecentlyBookmarkedHandler::SendBookmarksToPage() {
- std::vector<const BookmarkNode*> recently_bookmarked;
- bookmark_utils::GetMostRecentlyAddedEntries(
- model_, kRecentBookmarks, &recently_bookmarked);
- ListValue list_value;
- for (size_t i = 0; i < recently_bookmarked.size(); ++i) {
- const BookmarkNode* node = recently_bookmarked[i];
- DictionaryValue* entry_value = new DictionaryValue;
- NewTabUI::SetURLTitleAndDirection(entry_value,
- WideToUTF16(node->GetTitle()), node->GetURL());
- entry_value->SetReal(L"time", node->date_added().ToDoubleT());
- list_value.Append(entry_value);
- }
- dom_ui_->CallJavascriptFunction(L"recentlyBookmarked", list_value);
-}
-
-void RecentlyBookmarkedHandler::Loaded(BookmarkModel* model) {
- SendBookmarksToPage();
-}
-
-void RecentlyBookmarkedHandler::BookmarkNodeAdded(BookmarkModel* model,
- const BookmarkNode* parent,
- int index) {
- SendBookmarksToPage();
-}
-
-void RecentlyBookmarkedHandler::BookmarkNodeRemoved(BookmarkModel* model,
- const BookmarkNode* parent,
- int old_index,
- const BookmarkNode* node) {
- SendBookmarksToPage();
-}
-
-void RecentlyBookmarkedHandler::BookmarkNodeChanged(BookmarkModel* model,
- const BookmarkNode* node) {
- SendBookmarksToPage();
-}
-
-///////////////////////////////////////////////////////////////////////////////
// RecentlyClosedTabsHandler
class RecentlyClosedTabsHandler : public DOMMessageHandler,
@@ -681,50 +405,6 @@ bool RecentlyClosedTabsHandler::EnsureTabIsUnique(const DictionaryValue* tab,
return true;
}
-///////////////////////////////////////////////////////////////////////////////
-// HistoryHandler
-
-class HistoryHandler : public DOMMessageHandler {
- public:
- 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:
-
- DISALLOW_COPY_AND_ASSIGN(HistoryHandler);
-};
-
-void HistoryHandler::RegisterMessages() {
- dom_ui_->RegisterMessageCallback("searchHistoryPage",
- NewCallback(this, &HistoryHandler::HandleSearchHistoryPage));
-}
-
-void HistoryHandler::HandleSearchHistoryPage(const Value* content) {
- if (content && content->GetType() == Value::TYPE_LIST) {
- const ListValue* list_value = static_cast<const ListValue*>(content);
- Value* list_member;
- if (list_value->Get(0, &list_member) &&
- list_member->GetType() == Value::TYPE_STRING) {
- const StringValue* string_value =
- static_cast<const StringValue*>(list_member);
- std::wstring wstring_value;
- if (string_value->GetAsString(&wstring_value)) {
- UserMetrics::RecordAction(L"NTP_SearchHistory", dom_ui_->GetProfile());
- dom_ui_->tab_contents()->controller().LoadURL(
- HistoryUI::GetHistoryURLWithSearchText(wstring_value),
- GURL(),
- PageTransition::LINK);
- // We are deleted by LoadURL, so do not call anything else.
- }
- }
- }
-}
///////////////////////////////////////////////////////////////////////////////
// MetricsHandler