summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
authorglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-25 17:47:58 +0000
committerglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-25 17:47:58 +0000
commit9e4c033c4f88780c47ebf13ab4b9f180bf63df29 (patch)
treedcea8183f667edf646f7584064a2ca86af573471 /chrome/browser/dom_ui
parentd7e85c5dd9c2c8dfb38d1e7c6aacb1c3bd0bf590 (diff)
downloadchromium_src-9e4c033c4f88780c47ebf13ab4b9f180bf63df29.zip
chromium_src-9e4c033c4f88780c47ebf13ab4b9f180bf63df29.tar.gz
chromium_src-9e4c033c4f88780c47ebf13ab4b9f180bf63df29.tar.bz2
Enable history and downloads by default, port NewTabUI from DOMUIHost to DOMUI.
NewTabUI is only included on OS(WIN) because DOMUI doesn't appear to have been ported. Review URL: http://codereview.chromium.org/28104 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10344 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/dom_ui.cc6
-rw-r--r--chrome/browser/dom_ui/dom_ui.h17
-rw-r--r--chrome/browser/dom_ui/dom_ui_contents.cc75
-rw-r--r--chrome/browser/dom_ui/dom_ui_contents.h11
-rw-r--r--chrome/browser/dom_ui/dom_ui_host.h16
-rw-r--r--chrome/browser/dom_ui/history_ui.cc25
-rw-r--r--chrome/browser/dom_ui/history_ui.h3
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.cc182
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.h73
9 files changed, 219 insertions, 189 deletions
diff --git a/chrome/browser/dom_ui/dom_ui.cc b/chrome/browser/dom_ui/dom_ui.cc
index 94116b3..22e3382 100644
--- a/chrome/browser/dom_ui/dom_ui.cc
+++ b/chrome/browser/dom_ui/dom_ui.cc
@@ -79,6 +79,12 @@ void DOMUI::RegisterMessageCallback(const std::string &message,
message_callbacks_.insert(std::make_pair(message, callback));
}
+void DOMUI::RequestOpenURL(const GURL& url,
+ const GURL& /* referer */,
+ WindowOpenDisposition disposition) {
+ get_contents()->OpenURL(url, GURL(), disposition, PageTransition::LINK);
+}
+
// DOMUI, protected: ----------------------------------------------------------
void DOMUI::AddMessageHandler(DOMMessageHandler* handler) {
diff --git a/chrome/browser/dom_ui/dom_ui.h b/chrome/browser/dom_ui/dom_ui.h
index a1b25ec..1de9c42 100644
--- a/chrome/browser/dom_ui/dom_ui.h
+++ b/chrome/browser/dom_ui/dom_ui.h
@@ -42,6 +42,20 @@ class DOMUI {
const Value& arg1,
const Value& arg2);
+ // Overriddable control over the contents.
+ // Favicon should be displayed normally.
+ virtual bool ShouldDisplayFavIcon() { return true; }
+ // No special bookmark bar behavior
+ virtual bool IsBookmarkBarAlwaysVisible() { return false; }
+ // When NTP gets the initial focus, focus the URL bar.
+ virtual void SetInitialFocus() {};
+ // Whether we want to display the page's URL.
+ virtual bool ShouldDisplayURL() { return true; }
+ // Hide the referrer.
+ virtual void RequestOpenURL(const GURL& url, const GURL&,
+ WindowOpenDisposition disposition);
+
+ DOMUIContents* get_contents() { return contents_; }
Profile* get_profile() { return contents_->profile(); }
protected:
@@ -69,7 +83,7 @@ class DOMUI {
class DOMMessageHandler {
public:
explicit DOMMessageHandler(DOMUI* dom_ui);
- virtual ~DOMMessageHandler();
+ virtual ~DOMMessageHandler() {};
protected:
// Adds "url" and "title" keys on incoming dictionary, setting title
@@ -90,5 +104,4 @@ class DOMMessageHandler {
DISALLOW_COPY_AND_ASSIGN(DOMMessageHandler);
};
-
#endif // CHROME_BROWSER_DOM_UI_H__
diff --git a/chrome/browser/dom_ui/dom_ui_contents.cc b/chrome/browser/dom_ui/dom_ui_contents.cc
index 8e401a0..68334bb 100644
--- a/chrome/browser/dom_ui/dom_ui_contents.cc
+++ b/chrome/browser/dom_ui/dom_ui_contents.cc
@@ -4,9 +4,11 @@
#include "chrome/browser/dom_ui/dom_ui_contents.h"
+#include "chrome/browser/debugger/debugger_contents.h"
#include "chrome/browser/dom_ui/dom_ui.h"
-#include "chrome/browser/dom_ui/history_ui.h"
#include "chrome/browser/dom_ui/downloads_ui.h"
+#include "chrome/browser/dom_ui/history_ui.h"
+#include "chrome/browser/dom_ui/new_tab_ui.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/common/resource_bundle.h"
@@ -74,7 +76,7 @@ void FavIconSource::OnFavIconDataAvailable(
}
///////////////////////////////////////////////////////////////////////////////
-// ThumbnailSource
+// ThumbnailSource
ThumbnailSource::ThumbnailSource(Profile* profile)
: DataSource(kThumbnailPath, MessageLoop::current()), profile_(profile) {}
@@ -123,12 +125,8 @@ void ThumbnailSource::OnThumbnailDataAvailable(
// at the same host/path.
bool DOMUIContentsCanHandleURL(GURL* url,
TabContentsType* result_type) {
- if (!url->SchemeIs(kURLScheme))
- return false;
-
- // TODO: remove once the debugger is using DOMContentsUI
- if (url->host().compare("inspector") == 0 &&
- url->path().compare("/debugger.html") == 0)
+ // chrome-internal is a scheme we used to use for the new tab page.
+ if (!url->SchemeIs(kURLScheme) && !url->SchemeIs("chrome-internal"))
return false;
*result_type = TAB_CONTENTS_DOM_UI;
@@ -171,6 +169,35 @@ WebPreferences DOMUIContents::GetWebkitPrefs() {
return web_prefs;
}
+bool DOMUIContents::ShouldDisplayFavIcon() {
+ if (current_ui_)
+ return current_ui_->ShouldDisplayFavIcon();
+ return true;
+}
+
+bool DOMUIContents::IsBookmarkBarAlwaysVisible() {
+ if (current_ui_)
+ return current_ui_->IsBookmarkBarAlwaysVisible();
+ return false;
+}
+
+void DOMUIContents::SetInitialFocus() {
+ if (current_ui_)
+ current_ui_->SetInitialFocus();
+}
+
+bool DOMUIContents::ShouldDisplayURL() {
+ if (current_ui_)
+ return current_ui_->ShouldDisplayURL();
+ return true;
+}
+
+void DOMUIContents::RequestOpenURL(const GURL& url, const GURL& referrer,
+ WindowOpenDisposition disposition) {
+ if (current_ui_)
+ current_ui_->RequestOpenURL(url, referrer, disposition);
+}
+
bool DOMUIContents::NavigateToPendingEntry(bool reload) {
if (current_ui_) {
// Shut down our existing DOMUI.
@@ -190,20 +217,6 @@ bool DOMUIContents::NavigateToPendingEntry(bool reload) {
return WebContents::NavigateToPendingEntry(reload);
}
-DOMUI* DOMUIContents::GetDOMUIForURL(const GURL &url) {
-#if defined(OS_WIN)
-// TODO(port): Include when history and downloads are HTML UI.
- if (url.host() == HistoryUI::GetBaseURL().host())
- return new HistoryUI(this);
- else if (url.host() == DownloadsUI::GetBaseURL().host())
- return new DownloadsUI(this);
-#else
- NOTIMPLEMENTED();
-#endif
-
- return NULL;
-}
-
void DOMUIContents::ProcessDOMUIMessage(const std::string& message,
const std::string& content) {
DCHECK(current_ui_);
@@ -215,3 +228,21 @@ const std::string DOMUIContents::GetScheme() {
return kURLScheme;
}
+DOMUI* DOMUIContents::GetDOMUIForURL(const GURL &url) {
+#if defined(OS_WIN)
+// TODO(port): include this once these are converted to HTML
+ if (url.host() == NewTabUI::GetBaseURL().host() ||
+ url.SchemeIs("chrome-internal")) {
+ return new NewTabUI(this);
+ } else if (url.host() == HistoryUI::GetBaseURL().host()) {
+ return new HistoryUI(this);
+ } else if (url.host() == DownloadsUI::GetBaseURL().host()) {
+ return new DownloadsUI(this);
+ } else if (url.host() == DebuggerContents::GetBaseURL().host()) {
+ return new DebuggerContents(this);
+ }
+#else
+ NOTIMPLEMENTED();
+#endif
+ return NULL;
+}
diff --git a/chrome/browser/dom_ui/dom_ui_contents.h b/chrome/browser/dom_ui/dom_ui_contents.h
index 6f8bcb3..8220b175c 100644
--- a/chrome/browser/dom_ui/dom_ui_contents.h
+++ b/chrome/browser/dom_ui/dom_ui_contents.h
@@ -101,6 +101,17 @@ class DOMUIContents : public WebContents {
// Override this method so we can ensure that javascript and image loading
// are always on even for DOMUIHost tabs.
virtual WebPreferences GetWebkitPrefs();
+ // We don't want a favicon on the new tab page.
+ virtual bool ShouldDisplayFavIcon();
+ // The bookmark bar is always visible on the new tab.
+ virtual bool IsBookmarkBarAlwaysVisible();
+ // When NTP gets the initial focus, focus the URL bar.
+ virtual void SetInitialFocus();
+ // Whether we want to display the page's URL.
+ virtual bool ShouldDisplayURL();
+ // We may wish to control what happens when a URL is opened.
+ virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
+ WindowOpenDisposition disposition);
//
// TabContents overrides
diff --git a/chrome/browser/dom_ui/dom_ui_host.h b/chrome/browser/dom_ui/dom_ui_host.h
index 6d03915..cb49eef 100644
--- a/chrome/browser/dom_ui/dom_ui_host.h
+++ b/chrome/browser/dom_ui/dom_ui_host.h
@@ -2,16 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// DOMUIHost is a special type of TabContents that can display Chrome-specific
-// content using HTML.
-// It provides methods to send data to and from the page Javascript.
-
-// TODO(evanm): Add more limitations on what the contents of this view
-// can do (especially regarding network requests).
+// THIS FILE IS DEPRECATED, USE DOM_UI INSTEAD.
#ifndef CHROME_BROWSER_DOM_UI_DOM_UI_HOST_H__
#define CHROME_BROWSER_DOM_UI_DOM_UI_HOST_H__
+#include "chrome/browser/dom_ui/dom_ui.h"
#include "chrome/browser/tab_contents/web_contents.h"
#include "webkit/glue/webpreferences.h"
@@ -20,14 +16,6 @@ class RenderProcessHost;
class RenderViewHost;
class Value;
-// Messages sent from the DOM are forwarded via the DOMUIHost to handler
-// classes. These objects are owned by DOMUIHost and destroyed when the
-// host is destroyed.
-class DOMMessageHandler {
- public:
- virtual ~DOMMessageHandler() {}
-};
-
// See the comments at the top of this file.
class DOMUIHost : public WebContents {
public:
diff --git a/chrome/browser/dom_ui/history_ui.cc b/chrome/browser/dom_ui/history_ui.cc
index c1c0805..fcabc19 100644
--- a/chrome/browser/dom_ui/history_ui.cc
+++ b/chrome/browser/dom_ui/history_ui.cc
@@ -19,6 +19,8 @@
#include "chrome/common/notification_service.h"
#include "chrome/common/resource_bundle.h"
#include "chrome/common/time_format.h"
+#include "net/base/escape.h"
+
#include "grit/browser_resources.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
@@ -29,7 +31,7 @@ using base::TimeDelta;
// HistoryUI is accessible from chrome-ui://history.
static const char kHistoryHost[] = "history";
-// Maximum number of search results to return in a given search. We should
+// Maximum number of search results to return in a given search. We should
// eventually remove this.
static const int kMaxSearchResults = 100;
@@ -145,7 +147,7 @@ void BrowsingHistoryHandler::HandleGetHistory(const Value* value) {
dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
hs->QueryHistory(search_text_,
options,
- &cancelable_consumer_,
+ &cancelable_consumer_,
NewCallback(this, &BrowsingHistoryHandler::QueryComplete));
}
@@ -172,7 +174,7 @@ void BrowsingHistoryHandler::HandleSearchHistory(const Value* value) {
dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
hs->QueryHistory(search_text_,
options,
- &cancelable_consumer_,
+ &cancelable_consumer_,
NewCallback(this, &BrowsingHistoryHandler::QueryComplete));
}
@@ -217,11 +219,11 @@ void BrowsingHistoryHandler::QueryComplete(
SetURLAndTitle(page_value, page.title(), page.url());
// Need to pass the time in epoch time (fastest JS conversion).
- page_value->SetInteger(L"time",
+ page_value->SetInteger(L"time",
static_cast<int>(page.visit_time().ToTimeT()));
// Until we get some JS i18n infrastructure, we also need to
- // pass the dates in as strings. This could use some
+ // pass the dates in as strings. This could use some
// optimization.
// Only pass in the strings we need (search results need a shortdate
@@ -238,10 +240,10 @@ void BrowsingHistoryHandler::QueryComplete(
date_str, base::TimeFormatFriendlyDate(page.visit_time()));
}
page_value->SetString(L"dateRelativeDay", date_str);
- page_value->SetString(L"dateTimeOfDay",
+ page_value->SetString(L"dateTimeOfDay",
base::TimeFormatTimeOfDay(page.visit_time()));
} else {
- page_value->SetString(L"dateShort",
+ page_value->SetString(L"dateShort",
base::TimeFormatShortDate(page.visit_time()));
page_value->SetString(L"snippet", page.snippet().text());
}
@@ -253,7 +255,7 @@ void BrowsingHistoryHandler::QueryComplete(
dom_ui_->CallJavascriptFunction(L"historyResult", temp, results_value);
}
-void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value,
+void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value,
int* month, std::wstring* query) {
*month = 0;
@@ -364,3 +366,10 @@ GURL HistoryUI::GetBaseURL() {
url += kHistoryHost;
return GURL(url);
}
+
+// static
+const GURL HistoryUI::GetHistoryURLWithSearchText(
+ const std::wstring& text) {
+ return GURL(GetBaseURL().spec() + "/?q=" +
+ EscapeQueryParamValue(WideToUTF8(text)));
+}
diff --git a/chrome/browser/dom_ui/history_ui.h b/chrome/browser/dom_ui/history_ui.h
index 133cb96..d6bed47 100644
--- a/chrome/browser/dom_ui/history_ui.h
+++ b/chrome/browser/dom_ui/history_ui.h
@@ -85,6 +85,9 @@ class HistoryUI : public DOMUI {
// Return the URL for the front page of this UI.
static GURL GetBaseURL();
+ // Return the URL for a given search term.
+ static const GURL GetHistoryURLWithSearchText(const std::wstring& text);
+
// DOMUI Implementation
virtual void Init();
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc
index bcee162..2fc1571 100644
--- a/chrome/browser/dom_ui/new_tab_ui.cc
+++ b/chrome/browser/dom_ui/new_tab_ui.cc
@@ -14,7 +14,7 @@
#include "chrome/browser/dom_ui/dom_ui_contents.h"
#if defined(OS_WIN)
// TODO(port): include this once history is converted to HTML
-#include "chrome/browser/history_tab_ui.h"
+#include "chrome/browser/dom_ui/history_ui.h"
#endif
#include "chrome/browser/history/page_usage_data.h"
#include "chrome/browser/metrics/user_metrics.h"
@@ -38,8 +38,8 @@
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
-// The URL scheme used for the new tab.
-static const char kNewTabUIScheme[] = "chrome-internal";
+// NewTabUI is accessible from chrome-ui://newtab.
+static const char kNewTabHost[] = "newtab";
// The number of most visited pages we show.
const int kMostVisitedPages = 9;
@@ -177,7 +177,7 @@ void SetURLTitleAndDirection(DictionaryValue* dictionary,
// NewTabHTMLSource
NewTabHTMLSource::NewTabHTMLSource()
- : DataSource("new-tab", MessageLoop::current()) {
+ : DataSource(kNewTabHost, MessageLoop::current()) {
}
void NewTabHTMLSource::StartDataRequest(const std::string& path,
@@ -289,11 +289,12 @@ void IncognitoTabHTMLSource::StartDataRequest(const std::string& path,
///////////////////////////////////////////////////////////////////////////////
// MostVisitedHandler
-MostVisitedHandler::MostVisitedHandler(DOMUIHost* dom_ui_host)
- : dom_ui_host_(dom_ui_host) {
+MostVisitedHandler::MostVisitedHandler(DOMUI* dom_ui)
+ : DOMMessageHandler(dom_ui),
+ dom_ui_(dom_ui) {
// Register ourselves as the handler for the "mostvisited" message from
// Javascript.
- dom_ui_host_->RegisterMessageCallback("getMostVisited",
+ dom_ui_->RegisterMessageCallback("getMostVisited",
NewCallback(this, &MostVisitedHandler::HandleGetMostVisited));
// Set up our sources for thumbnail and favicon data.
@@ -301,27 +302,27 @@ MostVisitedHandler::MostVisitedHandler(DOMUIHost* dom_ui_host)
g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
NewRunnableMethod(&chrome_url_data_manager,
&ChromeURLDataManager::AddDataSource,
- new ThumbnailSource(dom_ui_host->profile())));
+ new ThumbnailSource(dom_ui->get_profile())));
g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
NewRunnableMethod(&chrome_url_data_manager,
&ChromeURLDataManager::AddDataSource,
- new FavIconSource(dom_ui_host->profile())));
+ new FavIconSource(dom_ui->get_profile())));
// Get notifications when history is cleared.
NotificationService* service = NotificationService::current();
service->AddObserver(this, NotificationType::HISTORY_URLS_DELETED,
- Source<Profile>(dom_ui_host_->profile()));
+ Source<Profile>(dom_ui_->get_profile()));
}
MostVisitedHandler::~MostVisitedHandler() {
NotificationService* service = NotificationService::current();
service->RemoveObserver(this, NotificationType::HISTORY_URLS_DELETED,
- Source<Profile>(dom_ui_host_->profile()));
+ Source<Profile>(dom_ui_->get_profile()));
}
void MostVisitedHandler::HandleGetMostVisited(const Value* value) {
HistoryService* hs =
- dom_ui_host_->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
+ dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
hs->QuerySegmentUsageSince(
&cancelable_consumer_,
base::Time::Now() - base::TimeDelta::FromDays(kMostVisitedScope),
@@ -342,7 +343,7 @@ void MostVisitedHandler::OnSegmentUsageAvailable(
pages_value.Append(page_value);
most_visited_urls_.push_back(page.GetURL());
}
- dom_ui_host_->CallJavascriptFunction(L"mostVisitedPages", pages_value);
+ dom_ui_->CallJavascriptFunction(L"mostVisitedPages", pages_value);
}
void MostVisitedHandler::Observe(NotificationType type,
@@ -360,11 +361,13 @@ void MostVisitedHandler::Observe(NotificationType type,
///////////////////////////////////////////////////////////////////////////////
// TemplateURLHandler
-TemplateURLHandler::TemplateURLHandler(DOMUIHost* dom_ui_host)
- : dom_ui_host_(dom_ui_host), template_url_model_(NULL) {
- dom_ui_host->RegisterMessageCallback("getMostSearched",
+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_host->RegisterMessageCallback("doSearch",
+ dom_ui->RegisterMessageCallback("doSearch",
NewCallback(this, &TemplateURLHandler::HandleDoSearch));
}
@@ -377,7 +380,7 @@ 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_host_->profile()->GetTemplateURLModel();
+ template_url_model_ = dom_ui_->get_profile()->GetTemplateURLModel();
template_url_model_->AddObserver(this);
}
if (template_url_model_->loaded()) {
@@ -434,7 +437,8 @@ void TemplateURLHandler::HandleDoSearch(const Value* content) {
if (url.is_valid()) {
// Load the URL.
- dom_ui_host_->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::LINK);
+ dom_ui_->get_contents()->OpenURL(url, GURL(), CURRENT_TAB,
+ PageTransition::LINK);
// Record the user action
std::vector<const TemplateURL*> urls =
@@ -454,7 +458,7 @@ void TemplateURLHandler::HandleDoSearch(const Value* content) {
if (urls[i] == template_url) {
UserMetrics::RecordComputedAction(
StringPrintf(L"NTP_SearchURL%d", item_number),
- dom_ui_host_->profile());
+ dom_ui_->get_profile());
break;
}
@@ -486,16 +490,17 @@ void TemplateURLHandler::OnTemplateURLModelChanged() {
urls_value.Append(entry_value);
}
UMA_HISTOGRAM_COUNTS("NewTabPage.SearchURLs.Total", urls_value.GetSize());
- dom_ui_host_->CallJavascriptFunction(L"searchURLs", urls_value);
+ dom_ui_->CallJavascriptFunction(L"searchURLs", urls_value);
}
///////////////////////////////////////////////////////////////////////////////
// RecentlyBookmarkedHandler
-RecentlyBookmarkedHandler::RecentlyBookmarkedHandler(DOMUIHost* dom_ui_host)
- : dom_ui_host_(dom_ui_host),
+RecentlyBookmarkedHandler::RecentlyBookmarkedHandler(DOMUI* dom_ui)
+ : DOMMessageHandler(dom_ui),
+ dom_ui_(dom_ui),
model_(NULL) {
- dom_ui_host->RegisterMessageCallback("getRecentlyBookmarked",
+ dom_ui->RegisterMessageCallback("getRecentlyBookmarked",
NewCallback(this,
&RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked));
}
@@ -507,7 +512,7 @@ RecentlyBookmarkedHandler::~RecentlyBookmarkedHandler() {
void RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked(const Value*) {
if (!model_) {
- model_ = dom_ui_host_->profile()->GetBookmarkModel();
+ model_ = dom_ui_->get_profile()->GetBookmarkModel();
model_->AddObserver(this);
}
// If the model is loaded, synchronously send the bookmarks down. Otherwise
@@ -527,7 +532,7 @@ void RecentlyBookmarkedHandler::SendBookmarksToPage() {
SetURLTitleAndDirection(entry_value, node->GetTitle(), node->GetURL());
list_value.Append(entry_value);
}
- dom_ui_host_->CallJavascriptFunction(L"recentlyBookmarked", list_value);
+ dom_ui_->CallJavascriptFunction(L"recentlyBookmarked", list_value);
}
void RecentlyBookmarkedHandler::Loaded(BookmarkModel* model) {
@@ -554,13 +559,14 @@ void RecentlyBookmarkedHandler::BookmarkNodeChanged(BookmarkModel* model,
///////////////////////////////////////////////////////////////////////////////
// RecentlyClosedTabsHandler
-RecentlyClosedTabsHandler::RecentlyClosedTabsHandler(DOMUIHost* dom_ui_host)
- : dom_ui_host_(dom_ui_host),
+RecentlyClosedTabsHandler::RecentlyClosedTabsHandler(DOMUI* dom_ui)
+ : DOMMessageHandler(dom_ui),
+ dom_ui_(dom_ui),
tab_restore_service_(NULL) {
- dom_ui_host->RegisterMessageCallback("getRecentlyClosedTabs",
+ dom_ui->RegisterMessageCallback("getRecentlyClosedTabs",
NewCallback(this,
&RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs));
- dom_ui_host->RegisterMessageCallback("reopenTab",
+ dom_ui->RegisterMessageCallback("reopenTab",
NewCallback(this, &RecentlyClosedTabsHandler::HandleReopenTab));
}
@@ -570,7 +576,7 @@ RecentlyClosedTabsHandler::~RecentlyClosedTabsHandler() {
}
void RecentlyClosedTabsHandler::HandleReopenTab(const Value* content) {
- NavigationController* controller = dom_ui_host_->controller();
+ NavigationController* controller = dom_ui_->get_contents()->controller();
Browser* browser = Browser::GetBrowserForController(
controller, NULL);
if (!browser)
@@ -603,7 +609,7 @@ void RecentlyClosedTabsHandler::HandleReopenTab(const Value* content) {
void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs(
const Value* content) {
if (!tab_restore_service_) {
- tab_restore_service_ = dom_ui_host_->profile()->GetTabRestoreService();
+ tab_restore_service_ = dom_ui_->get_profile()->GetTabRestoreService();
// GetTabRestoreService() can return NULL (i.e., when in Off the
// Record mode)
@@ -645,7 +651,7 @@ void RecentlyClosedTabsHandler::TabRestoreServiceChanged(
delete value;
}
}
- dom_ui_host_->CallJavascriptFunction(L"recentlyClosedTabs", list_value);
+ dom_ui_->CallJavascriptFunction(L"recentlyClosedTabs", list_value);
}
void RecentlyClosedTabsHandler::TabRestoreServiceDestroyed(
@@ -661,7 +667,7 @@ bool RecentlyClosedTabsHandler::TabToValue(
const TabNavigation& current_navigation =
tab.navigations.at(tab.current_navigation_index);
- if (current_navigation.url() == NewTabUIURL())
+ if (current_navigation.url() == NewTabUI::GetBaseURL())
return false;
SetURLTitleAndDirection(dictionary, current_navigation.title(),
@@ -699,22 +705,23 @@ bool RecentlyClosedTabsHandler::WindowToValue(
///////////////////////////////////////////////////////////////////////////////
// HistoryHandler
-HistoryHandler::HistoryHandler(DOMUIHost* dom_ui_host)
- : dom_ui_host_(dom_ui_host) {
- dom_ui_host->RegisterMessageCallback("showHistoryPage",
+HistoryHandler::HistoryHandler(DOMUI* dom_ui)
+ : DOMMessageHandler(dom_ui),
+ dom_ui_(dom_ui) {
+ dom_ui->RegisterMessageCallback("showHistoryPage",
NewCallback(this, &HistoryHandler::HandleShowHistoryPage));
- dom_ui_host->RegisterMessageCallback("searchHistoryPage",
+ dom_ui->RegisterMessageCallback("searchHistoryPage",
NewCallback(this, &HistoryHandler::HandleSearchHistoryPage));
}
void HistoryHandler::HandleShowHistoryPage(const Value*) {
- NavigationController* controller = dom_ui_host_->controller();
+ NavigationController* controller = dom_ui_->get_contents()->controller();
if (controller) {
#if defined(OS_WIN)
// TODO(port): include this once history is converted to HTML
- controller->LoadURL(HistoryTabUI::GetURL(), GURL(), PageTransition::LINK);
+ controller->LoadURL(HistoryUI::GetBaseURL(), GURL(), PageTransition::LINK);
UserMetrics::RecordAction(L"NTP_ShowHistory",
- dom_ui_host_->profile());
+ dom_ui_->get_profile());
#else
NOTIMPLEMENTED();
#endif
@@ -732,13 +739,14 @@ void HistoryHandler::HandleSearchHistoryPage(const Value* content) {
std::wstring wstring_value;
if (string_value->GetAsString(&wstring_value)) {
UserMetrics::RecordAction(L"NTP_SearchHistory",
- dom_ui_host_->profile());
+ dom_ui_->get_profile());
#if defined(OS_WIN)
// TODO(port): include this once history is converted to HTML
- NavigationController* controller = dom_ui_host_->controller();
+ NavigationController* controller =
+ dom_ui_->get_contents()->controller();
controller->LoadURL(
- HistoryTabUI::GetHistoryURLWithSearchText(wstring_value),
+ HistoryUI::GetHistoryURLWithSearchText(wstring_value),
GURL(),
PageTransition::LINK);
#else
@@ -752,9 +760,10 @@ void HistoryHandler::HandleSearchHistoryPage(const Value* content) {
///////////////////////////////////////////////////////////////////////////////
// MetricsHandler
-MetricsHandler::MetricsHandler(DOMUIHost* dom_ui_host)
- : dom_ui_host_(dom_ui_host) {
- dom_ui_host->RegisterMessageCallback("metrics",
+MetricsHandler::MetricsHandler(DOMUI* dom_ui)
+ : DOMMessageHandler(dom_ui),
+ dom_ui_(dom_ui) {
+ dom_ui->RegisterMessageCallback("metrics",
NewCallback(this, &MetricsHandler::HandleMetrics));
}
@@ -769,7 +778,7 @@ void MetricsHandler::HandleMetrics(const Value* content) {
std::wstring wstring_value;
if (string_value->GetAsString(&wstring_value)) {
UserMetrics::RecordComputedAction(wstring_value,
- dom_ui_host_->profile());
+ dom_ui_->get_profile());
}
}
}
@@ -778,33 +787,11 @@ void MetricsHandler::HandleMetrics(const Value* content) {
///////////////////////////////////////////////////////////////////////////////
// NewTabUIContents
-// This is the top-level URL handler for chrome-internal: URLs, and exposed in
-// our header file.
-bool NewTabUIHandleURL(GURL* url,
- TabContentsType* result_type) {
- if (!url->SchemeIs(kNewTabUIScheme))
- return false;
-
- *result_type = TAB_CONTENTS_NEW_TAB_UI;
- *url = GURL(DOMUIContents::GetScheme() + "://new-tab/");
-
- return true;
-}
-
-GURL NewTabUIURL() {
- std::string url(kNewTabUIScheme);
- url += ":";
- return GURL(url);
-}
-
-NewTabUIContents::NewTabUIContents(Profile* profile,
- SiteInstance* instance, RenderViewHostFactory* render_view_factory) :
- DOMUIHost(profile, instance, render_view_factory),
+NewTabUI::NewTabUI(DOMUIContents* contents) :
+ DOMUI(contents),
motd_message_id_(0),
incognito_(false),
most_visited_handler_(NULL) {
- set_type(TAB_CONTENTS_NEW_TAB_UI);
-
// Show profile name in the title if the current profile is not the default.
std::wstring title;
if (UserDataManager::Get()->is_current_profile_default()) {
@@ -816,20 +803,20 @@ NewTabUIContents::NewTabUIContents(Profile* profile,
}
set_forced_title(title);
- if (profile->IsOffTheRecord())
+ if (get_profile()->IsOffTheRecord())
incognito_ = true;
if (NewTabHTMLSource::first_view() &&
- (profile->GetPrefs()->GetInteger(prefs::kRestoreOnStartup) != 0 ||
- !profile->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage))
+ (get_profile()->GetPrefs()->GetInteger(prefs::kRestoreOnStartup) != 0 ||
+ !get_profile()->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage))
) {
NewTabHTMLSource::set_first_view(false);
}
- render_view_host()->set_paint_observer(new PaintTimer);
+ contents->render_view_host()->set_paint_observer(new PaintTimer);
}
-void NewTabUIContents::AttachMessageHandlers() {
+void NewTabUI::Init() {
// Regretfully, DataSources are global, instead of
// per-TabContents. Because of the motd_message_id_ member, each
// NewTabUIContents instance could theoretically have a different
@@ -871,36 +858,27 @@ void NewTabUIContents::AttachMessageHandlers() {
}
}
-bool NewTabUIContents::NavigateToPendingEntry(bool reload) {
- const bool result = WebContents::NavigateToPendingEntry(reload);
- controller()->GetPendingEntry()->set_title(forced_title_);
- return result;
-}
-
-const std::wstring& NewTabUIContents::GetTitle() const {
- if (!forced_title_.empty())
- return forced_title_;
- return WebContents::GetTitle();
-}
-
-void NewTabUIContents::SetInitialFocus() {
- if (delegate())
- delegate()->SetFocusToLocationBar();
+// static
+GURL NewTabUI::GetBaseURL() {
+ std::string url = DOMUIContents::GetScheme();
+ url += "://";
+ url += kNewTabHost;
+ return GURL(url);
}
-bool NewTabUIContents::SupportsURL(GURL* url) {
- if (url->SchemeIs("javascript"))
- return true;
- return DOMUIHost::SupportsURL(url);
+void NewTabUI::SetInitialFocus() {
+ if (get_contents()->delegate())
+ get_contents()->delegate()->SetFocusToLocationBar();
}
-void NewTabUIContents::RequestOpenURL(const GURL& url,
- const GURL& /*referrer*/,
- WindowOpenDisposition disposition) {
+void NewTabUI::RequestOpenURL(const GURL& url,
+ const GURL&,
+ WindowOpenDisposition disposition) {
// The user opened a URL on the page (including "open in new window").
// We count all such clicks as AUTO_BOOKMARK, which increments the site's
// visit count (which is used for ranking the most visited entries).
- // Note this means we're including clicks on not only most visited thumbnails,
- // but also clicks on recently bookmarked.
- OpenURL(url, GURL(), disposition, PageTransition::AUTO_BOOKMARK);
+ // Note this means we're including clicks on not only most visited
+ // thumbnails, but also clicks on recently bookmarked.
+ get_contents()->OpenURL(url, GURL(), disposition,
+ PageTransition::AUTO_BOOKMARK);
}
diff --git a/chrome/browser/dom_ui/new_tab_ui.h b/chrome/browser/dom_ui/new_tab_ui.h
index a44060e..597c59f 100644
--- a/chrome/browser/dom_ui/new_tab_ui.h
+++ b/chrome/browser/dom_ui/new_tab_ui.h
@@ -6,7 +6,7 @@
#define CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H__
#include "chrome/browser/bookmarks/bookmark_model.h"
-#include "chrome/browser/dom_ui/dom_ui_host.h"
+#include "chrome/browser/dom_ui/dom_ui.h"
#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/search_engines/template_url_model.h"
@@ -18,14 +18,6 @@ class Profile;
class Value;
enum TabContentsType;
-// Return the URL for the new tab page.
-GURL NewTabUIURL();
-
-// If a |url| is a chrome-internal: URL, this method sets up |url|, and
-// |result_type| to the appropriate values for displaying the new tab page
-// and returns true. Exposed for use by BrowserURLHandler.
-bool NewTabUIHandleURL(GURL* url, TabContentsType* result_type);
-
// The following classes aren't used outside of new_tab_ui.cc but are
// put here for clarity.
@@ -74,7 +66,7 @@ class IncognitoTabHTMLSource : public ChromeURLDataManager::DataSource {
class MostVisitedHandler : public DOMMessageHandler,
public NotificationObserver {
public:
- explicit MostVisitedHandler(DOMUIHost* dom_ui_host);
+ explicit MostVisitedHandler(DOMUI* dom_ui);
virtual ~MostVisitedHandler();
// Callback for the "getMostVisited" message.
@@ -94,7 +86,7 @@ class MostVisitedHandler : public DOMMessageHandler,
void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle,
std::vector<PageUsageData*>* data);
- DOMUIHost* dom_ui_host_;
+ DOMUI* dom_ui_;
// Our consumer for the history service.
CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_;
@@ -111,7 +103,7 @@ class MostVisitedHandler : public DOMMessageHandler,
class TemplateURLHandler : public DOMMessageHandler,
public TemplateURLModelObserver {
public:
- explicit TemplateURLHandler(DOMUIHost* dom_ui_host);
+ explicit TemplateURLHandler(DOMUI* dom_ui);
virtual ~TemplateURLHandler();
// Callback for the "getMostSearched" message, sent when the page requests
@@ -126,7 +118,7 @@ class TemplateURLHandler : public DOMMessageHandler,
virtual void OnTemplateURLModelChanged();
private:
- DOMUIHost* dom_ui_host_;
+ DOMUI* dom_ui_;
TemplateURLModel* template_url_model_; // Owned by profile.
DISALLOW_EVIL_CONSTRUCTORS(TemplateURLHandler);
@@ -135,7 +127,7 @@ class TemplateURLHandler : public DOMMessageHandler,
class RecentlyBookmarkedHandler : public DOMMessageHandler,
public BookmarkModelObserver {
public:
- explicit RecentlyBookmarkedHandler(DOMUIHost* dom_ui_host);
+ explicit RecentlyBookmarkedHandler(DOMUI* dom_ui);
~RecentlyBookmarkedHandler();
// Callback which navigates to the bookmarks page.
@@ -168,7 +160,7 @@ class RecentlyBookmarkedHandler : public DOMMessageHandler,
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
BookmarkNode* node) {}
- DOMUIHost* dom_ui_host_;
+ DOMUI* dom_ui_;
// The model we're getting bookmarks from. The model is owned by the Profile.
BookmarkModel* model_;
@@ -178,7 +170,7 @@ class RecentlyBookmarkedHandler : public DOMMessageHandler,
class RecentlyClosedTabsHandler : public DOMMessageHandler,
public TabRestoreService::Observer {
public:
- explicit RecentlyClosedTabsHandler(DOMUIHost* dom_ui_host);
+ explicit RecentlyClosedTabsHandler(DOMUI* dom_ui);
virtual ~RecentlyClosedTabsHandler();
// Callback for the "reopenTab" message. Rewrites the history of the
@@ -209,7 +201,7 @@ class RecentlyClosedTabsHandler : public DOMMessageHandler,
bool WindowToValue(const TabRestoreService::Window& window,
DictionaryValue* dictionary);
- DOMUIHost* dom_ui_host_;
+ DOMUI* dom_ui_;
/// TabRestoreService that we are observing.
TabRestoreService* tab_restore_service_;
@@ -219,7 +211,7 @@ class RecentlyClosedTabsHandler : public DOMMessageHandler,
class HistoryHandler : public DOMMessageHandler {
public:
- explicit HistoryHandler(DOMUIHost* dom_ui_host);
+ explicit HistoryHandler(DOMUI* dom_ui);
// Callback which navigates to the history page.
void HandleShowHistoryPage(const Value*);
@@ -228,7 +220,7 @@ class HistoryHandler : public DOMMessageHandler {
void HandleSearchHistoryPage(const Value* content);
private:
- DOMUIHost* dom_ui_host_;
+ DOMUI* dom_ui_;
DISALLOW_EVIL_CONSTRUCTORS(HistoryHandler);
};
@@ -240,22 +232,26 @@ class HistoryHandler : public DOMMessageHandler {
// information (treat it as RecordComputedMetrics)
class MetricsHandler : public DOMMessageHandler {
public:
- explicit MetricsHandler(DOMUIHost* dom_ui_host);
+ explicit MetricsHandler(DOMUI* dom_ui);
// Callback which records a user action.
void HandleMetrics(const Value* content);
private:
- DOMUIHost* dom_ui_host_;
+ DOMUI* dom_ui_;
DISALLOW_EVIL_CONSTRUCTORS(MetricsHandler);
};
// The TabContents used for the New Tab page.
-class NewTabUIContents : public DOMUIHost {
+class NewTabUI : public DOMUI {
public:
- NewTabUIContents(Profile* profile,
- SiteInstance* instance,
- RenderViewHostFactory* render_view_factory);
+ explicit NewTabUI(DOMUIContents* contents);
+
+ // Return the URL for the front page of this UI.
+ static GURL GetBaseURL();
+
+ // DOMUI Implementation
+ virtual void Init();
// Set the title that overrides any other title provided for the tab.
// This lets you set the title that's displayed before the content loads,
@@ -264,27 +260,22 @@ class NewTabUIContents : public DOMUIHost {
forced_title_ = title;
}
- // DOMUIHost implementation.
- virtual void AttachMessageHandlers();
-
- // WebContents overrides.
- // Overriden to force the title of the page to forced_title_.
- virtual bool NavigateToPendingEntry(bool reload);
- // We don't want a favicon on the new tab page.
+ // Overridden from DOMUI.
+ // Favicon should not be displayed.
virtual bool ShouldDisplayFavIcon() { return false; }
- // The bookmark bar is always visible on the new tab.
+ // Bookmark bar should always be visible.
virtual bool IsBookmarkBarAlwaysVisible() { return true; }
- // Return forced_title_ if it's available.
- virtual const std::wstring& GetTitle() const;
- // When we get the initial focus, focus the URL bar.
+ // When NTP gets the initial focus, focus the URL bar.
virtual void SetInitialFocus();
- // The URL bar should not display the current page's URL.
+ // Should not display our URL.
virtual bool ShouldDisplayURL() { return false; }
- virtual bool SupportsURL(GURL* url);
- // Clicking a URL on the page should count as an autobookmark click.
+ // Control what happens when a link is clicked.
virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
- WindowOpenDisposition disposition);
+ WindowOpenDisposition disposition);
+
private:
+ DOMUIContents* contents_;
+
// The message id that should be displayed in this NewTabUIContents
// instance's motd area.
int motd_message_id_;
@@ -301,7 +292,7 @@ class NewTabUIContents : public DOMUIHost {
// Owned by the DOMUIHost.
MostVisitedHandler* most_visited_handler_;
- DISALLOW_EVIL_CONSTRUCTORS(NewTabUIContents);
+ DISALLOW_EVIL_CONSTRUCTORS(NewTabUI);
};
#endif // CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H__