diff options
author | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-25 17:47:58 +0000 |
---|---|---|
committer | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-25 17:47:58 +0000 |
commit | 9e4c033c4f88780c47ebf13ab4b9f180bf63df29 (patch) | |
tree | dcea8183f667edf646f7584064a2ca86af573471 /chrome/browser | |
parent | d7e85c5dd9c2c8dfb38d1e7c6aacb1c3bd0bf590 (diff) | |
download | chromium_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')
-rw-r--r-- | chrome/browser/browser.cc | 20 | ||||
-rw-r--r-- | chrome/browser/browser_url_handler.cc | 4 | ||||
-rw-r--r-- | chrome/browser/debugger/debugger_contents.cc | 24 | ||||
-rw-r--r-- | chrome/browser/debugger/debugger_contents.h | 17 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui.cc | 6 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui.h | 17 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_contents.cc | 75 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_contents.h | 11 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_host.h | 16 | ||||
-rw-r--r-- | chrome/browser/dom_ui/history_ui.cc | 25 | ||||
-rw-r--r-- | chrome/browser/dom_ui/history_ui.h | 3 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 182 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.h | 73 | ||||
-rw-r--r-- | chrome/browser/resources/history.html | 53 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_blocking_page.cc | 2 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_factory.cc | 6 | ||||
-rw-r--r-- | chrome/browser/tabs/tab_strip_model_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/browser/views/download_shelf_view.cc | 2 | ||||
-rw-r--r-- | chrome/browser/views/options/general_page_view.cc | 3 |
19 files changed, 296 insertions, 247 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index a162a26..c4bc67b 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -12,6 +12,7 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_shutdown.h" +#include "chrome/browser/dom_ui/new_tab_ui.h" #include "chrome/browser/location_bar.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/net/url_fixer_upper.h" @@ -47,7 +48,6 @@ #endif #if defined(OS_WIN) - #include <windows.h> #include <shellapi.h> @@ -59,9 +59,9 @@ #include "chrome/browser/character_encoding.h" #include "chrome/browser/debugger/debugger_window.h" #include "chrome/browser/dock_info.h" -#include "chrome/browser/dom_ui/new_tab_ui.h" +#include "chrome/browser/dom_ui/downloads_ui.h" +#include "chrome/browser/dom_ui/history_ui.h" #include "chrome/browser/download/save_package.h" -#include "chrome/browser/history_tab_ui.h" #include "chrome/browser/options_window.h" #include "chrome/browser/ssl/ssl_error_info.h" #include "chrome/browser/tab_contents/web_contents_view.h" @@ -958,7 +958,9 @@ void Browser::ToggleBookmarkBar() { void Browser::ShowHistoryTab() { UserMetrics::RecordAction(L"ShowHistory", profile_); - ShowNativeUITab(HistoryTabUI::GetURL()); + GURL downloads_url = HistoryUI::GetBaseURL(); + AddTabWithURL(downloads_url, GURL(), PageTransition::AUTO_BOOKMARK, true, + NULL); } void Browser::OpenBookmarkManager() { @@ -968,7 +970,9 @@ void Browser::OpenBookmarkManager() { void Browser::ShowDownloadsTab() { UserMetrics::RecordAction(L"ShowDownloads", profile_); - ShowNativeUITab(DownloadTabUI::GetURL()); + GURL downloads_url = DownloadsUI::GetBaseURL(); + AddTabWithURL(downloads_url, GURL(), PageTransition::AUTO_BOOKMARK, true, + NULL); } void Browser::OpenClearBrowsingDataDialog() { @@ -1214,7 +1218,7 @@ void Browser::ExecuteCommand(int id) { // Browser, TabStripModelDelegate implementation: GURL Browser::GetBlankTabURL() const { - return NewTabUIURL(); + return NewTabUI::GetBaseURL(); } void Browser::CreateNewStripWithContents(TabContents* detached_contents, @@ -2372,12 +2376,12 @@ void Browser::BuildPopupWindow(TabContents* source, GURL Browser::GetHomePage() { if (profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) - return NewTabUIURL(); + return NewTabUI::GetBaseURL(); GURL home_page = GURL(URLFixerUpper::FixupURL( WideToUTF8(profile_->GetPrefs()->GetString(prefs::kHomePage)), std::string())); if (!home_page.is_valid()) - return NewTabUIURL(); + return NewTabUI::GetBaseURL(); return home_page; } diff --git a/chrome/browser/browser_url_handler.cc b/chrome/browser/browser_url_handler.cc index 1cc4344..98bdaa0 100644 --- a/chrome/browser/browser_url_handler.cc +++ b/chrome/browser/browser_url_handler.cc @@ -5,7 +5,6 @@ #include "chrome/browser/browser_url_handler.h" #include "chrome/browser/browser_about_handler.h" -#include "chrome/browser/dom_ui/new_tab_ui.h" #include "chrome/browser/dom_ui/dom_ui_contents.h" std::vector<BrowserURLHandler::URLHandler> BrowserURLHandler::url_handlers_; @@ -18,8 +17,6 @@ void BrowserURLHandler::InitURLHandlers() { // Here is where we initialize the global list of handlers for special URLs. // about:* url_handlers_.push_back(&BrowserAboutHandler::MaybeHandle); - // chrome-internal:* - url_handlers_.push_back(&NewTabUIHandleURL); // chrome-ui:* url_handlers_.push_back(&DOMUIContentsCanHandleURL); } @@ -35,4 +32,3 @@ bool BrowserURLHandler::HandleBrowserURL(GURL* url, TabContentsType* type) { return false; } - diff --git a/chrome/browser/debugger/debugger_contents.cc b/chrome/browser/debugger/debugger_contents.cc index 19565e8..386b5d8 100644 --- a/chrome/browser/debugger/debugger_contents.cc +++ b/chrome/browser/debugger/debugger_contents.cc @@ -19,6 +19,9 @@ #include "grit/debugger_resources.h" +// DebuggerUI is accessible from chrome-ui://inspector. +static const char kDebuggerHost[] = "inspector"; + class DebuggerHTMLSource : public ChromeURLDataManager::DataSource { public: // Creates our datasource and sets our user message to a specific message @@ -86,8 +89,8 @@ class DebuggerHTMLSource : public ChromeURLDataManager::DataSource { class DebuggerHandler : public DOMMessageHandler { public: - explicit DebuggerHandler(DOMUIHost* host) { - host->RegisterMessageCallback("DebuggerHostMessage", + explicit DebuggerHandler(DOMUI* dom_ui) : DOMMessageHandler(dom_ui) { + dom_ui->RegisterMessageCallback("DebuggerHostMessage", NewCallback(this, &DebuggerHandler::HandleDebuggerHostMessage)); } @@ -118,12 +121,11 @@ class DebuggerHandler : public DOMMessageHandler { }; -DebuggerContents::DebuggerContents(Profile* profile, SiteInstance* instance) - : DOMUIHost(profile, instance, NULL) { - set_type(TAB_CONTENTS_DEBUGGER); +DebuggerContents::DebuggerContents(DOMUIContents* contents) + : DOMUI(contents) { } -void DebuggerContents::AttachMessageHandlers() { +void DebuggerContents::Init() { AddMessageHandler(new DebuggerHandler(this)); DebuggerHTMLSource* html_source = new DebuggerHTMLSource(); @@ -135,6 +137,14 @@ void DebuggerContents::AttachMessageHandlers() { // static bool DebuggerContents::IsDebuggerUrl(const GURL& url) { - return (url.SchemeIs("chrome-ui") && url.host() == "inspector"); + return (url.SchemeIs(DOMUIContents::GetScheme().c_str()) && + url.host() == kDebuggerHost); } +// static +GURL DebuggerContents::GetBaseURL() { + std::string url = DOMUIContents::GetScheme(); + url += "://"; + url += kDebuggerHost; + return GURL(url); +} diff --git a/chrome/browser/debugger/debugger_contents.h b/chrome/browser/debugger/debugger_contents.h index af29f6a..69c33fd 100644 --- a/chrome/browser/debugger/debugger_contents.h +++ b/chrome/browser/debugger/debugger_contents.h @@ -7,24 +7,29 @@ #ifndef CHROME_BROWSER_SHELL_DEBUGGER_CONTENTS_H__ #define CHROME_BROWSER_SHELL_DEBUGGER_CONTENTS_H__ -#include "chrome/browser/dom_ui/dom_ui_host.h" +#include "chrome/browser/dom_ui/dom_ui.h" -class DebuggerContents : public DOMUIHost { +class DebuggerContents : public DOMUI { public: - DebuggerContents(Profile* profile, SiteInstance* instance); + DebuggerContents(DOMUIContents* contents); + + // DOMUI Implementation + virtual void Init(); + + // Return the URL for the front page of this UI. + static GURL GetBaseURL(); static bool IsDebuggerUrl(const GURL& url); protected: + DOMUIContents* contents_; + // WebContents overrides: // We override updating history with a no-op so these pages // are not saved to history. virtual void UpdateHistoryForNavigation(const GURL& url, const ViewHostMsg_FrameNavigate_Params& params) { } - // DOMUIHost implementation. - virtual void AttachMessageHandlers(); - DISALLOW_EVIL_CONSTRUCTORS(DebuggerContents); }; 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__ diff --git a/chrome/browser/resources/history.html b/chrome/browser/resources/history.html index 6bc8d5c..4324d2c 100644 --- a/chrome/browser/resources/history.html +++ b/chrome/browser/resources/history.html @@ -9,7 +9,7 @@ var RESULTS_PER_PAGE = 150; var MAX_SEARCH_DEPTH_MONTHS = 18; -// Amount of time between pageviews that we consider a 'break' in browsing, +// Amount of time between pageviews that we consider a 'break' in browsing, // measured in milliseconds. var BROWSING_GAP_TIME = 15 * 60 * 1000; @@ -32,7 +32,7 @@ var pageState; */ function LocalStrings(node) { this.strings_ = {}; - + var children = node.childNodes; for (var i = 0, child; child = children[i]; i++) { var id = child.id; @@ -52,7 +52,7 @@ LocalStrings.prototype.getString = function(s) { } /** - * Returns a formatted localized string (where all %s contents are replaced + * Returns a formatted localized string (where all %s contents are replaced * by the second argument). * @param {string} s The id of the string we want * @param {string} d The string to include in the formatted string @@ -75,10 +75,12 @@ function Page(result, continued, model) { this.title_ = result.title; this.url_ = result.url; this.snippet_ = result.snippet || ""; - + + this.changed = false; + // All the date information is public so that owners can compare properties of // two items easily. - + // We get the time in seconds, but we want it in milliseconds. this.time = new Date(result.time * 1000); @@ -272,7 +274,7 @@ HistoryModel.prototype.addResults = function(term, results) { for (var i = 0, thisResult; thisResult = results[i]; i++) { var thisURL = thisResult.url; var thisDay = thisResult.dateRelativeDay; - + // Remove adjacent duplicates. if (!lastURL || lastURL != thisURL) { // Figure out if this page is in the same day as the previous page, @@ -283,6 +285,8 @@ HistoryModel.prototype.addResults = function(term, results) { } } } + if (results.length) + this.changed = true; this.updateSearch_(); } @@ -341,6 +345,7 @@ HistoryModel.prototype.updateSearch_ = function() { // We have maxed out. There will be no more data. this.complete_ = true; this.view_.onModelReady(); + this.changed = false; } else { // If we can't fill the requested page, ask for more data unless a request // is still in-flight. @@ -349,8 +354,9 @@ HistoryModel.prototype.updateSearch_ = function() { } // If we have any data for the requested page, show it. - if (this.haveDataForPage_(this.requestedPage_)) { + if (this.changed && this.haveDataForPage_(this.requestedPage_)) { this.view_.onModelReady(); + this.changed = false; } } } @@ -367,15 +373,15 @@ HistoryModel.prototype.updateSearch_ = function() { */ HistoryModel.prototype.getSearchResults_ = function(depth) { this.searchDepth_ = depth || 0; - + if (this.searchText_ == "") { chrome.send('getHistory', [String(this.searchDepth_)]); } else { chrome.send('searchHistory', - [this.searchText_, String(this.searchDepth_)]); + [this.searchText_, String(this.searchDepth_)]); } - + this.inFlight_ = true; } @@ -412,7 +418,8 @@ function HistoryView(model) { this.pageDiv_ = $('results-pagination'); this.model_ = model this.pageIndex_ = 0; - + this.lastDisplayed_ = []; + this.model_.setView(this); } @@ -486,21 +493,21 @@ HistoryView.prototype.displayResults_ = function() { for (var i = 0, page; page = results[i]; i++) { // Break across day boundaries and insert gaps for browsing pauses. var thisTime = page.time.getTime(); - + if ((i == 0 && page.continued) || !page.continued) { output.push('<div class="day">' + page.dateRelativeDay); - + if (i == 0 && page.continued) output.push(' ' + localStrings.getString('cont')); - + output.push('<a href="#" class="delete-day" ' + - 'onclick="return deleteDay(\'' + + 'onclick="return deleteDay(\'' + page.time.toString() + '\');">' + localStrings.getString("deleteday") + '</a>'); output.push('</div>'); } else if (lastTime - thisTime > BROWSING_GAP_TIME) { output.push('<div class="gap"></div>'); - } + } lastTime = thisTime; // Draw entry. @@ -532,11 +539,11 @@ HistoryView.prototype.displayNavBar_ = function() { var navOutput = ''; if (this.pageIndex_ > 0) { navOutput += this.createPageNavHTML_(0, localStrings.getString('newest')); - navOutput += this.createPageNavHTML_(this.pageIndex_ - 1, + navOutput += this.createPageNavHTML_(this.pageIndex_ - 1, localStrings.getString('newer')); } if (this.model_.getSize() > (this.pageIndex_ + 1) * RESULTS_PER_PAGE) { - navOutput += this.createPageNavHTML_(this.pageIndex_ + 1, + navOutput += this.createPageNavHTML_(this.pageIndex_ + 1, localStrings.getString('older')); } this.pageDiv_.innerHTML = navOutput; @@ -570,10 +577,10 @@ function PageState(model, view) { if (PageState.instance) { return PageState.instance; } - + this.model = model; this.view = view; - + if (typeof this.checker_ != 'undefined' && this.checker_) { clearInterval(this.checker_); } @@ -582,7 +589,7 @@ function PageState(model, view) { // public model and view. this.checker_ = setInterval((function(state_obj) { var hashData = state_obj.getHashData(); - + if (hashData.q != state_obj.model.getSearchText(term)) { state_obj.view.setSearch(hashData.q, parseInt(hashData.p, 10)); } else if (parseInt(hashData.p, 10) != state_obj.view.getPage()) { @@ -656,13 +663,13 @@ PageState.getHashString = function(term, page) { // Document Functions: /** * Window onload handler, sets up the page. - */ + */ function load() { localStrings = new LocalStrings($('l10n')); historyModel = new HistoryModel(); historyView = new HistoryView(historyModel); pageState = new PageState(historyModel, historyView); - + // Create default view. var hashData = pageState.getHashData(); historyView.setSearch(hashData.q, hashData.p); diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc index 9d912bf..2eafe9a1 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc @@ -377,7 +377,7 @@ void SafeBrowsingBlockingPage::DontProceed() { // for the tab has by then already been destroyed. if (navigation_entry_index_to_remove_ != -1 && !tab()->is_being_destroyed()) { tab()->controller()->RemoveEntryAtIndex(navigation_entry_index_to_remove_, - NewTabUIURL()); + NewTabUI::GetBaseURL()); navigation_entry_index_to_remove_ = -1; } InterstitialPage::DontProceed(); diff --git a/chrome/browser/tab_contents/tab_contents_factory.cc b/chrome/browser/tab_contents/tab_contents_factory.cc index e6aa1a2..9a5063f 100644 --- a/chrome/browser/tab_contents/tab_contents_factory.cc +++ b/chrome/browser/tab_contents/tab_contents_factory.cc @@ -52,9 +52,6 @@ TabContents* TabContents::CreateWithType(TabContentsType type, // TODO(port): remove this platform define, either by porting the tab contents // types or removing them completely. #if defined(OS_WIN) - case TAB_CONTENTS_NEW_TAB_UI: - contents = new NewTabUIContents(profile, instance, NULL); - break; case TAB_CONTENTS_HTML_DIALOG: contents = new HtmlDialogContents(profile, instance, NULL); break; @@ -68,8 +65,7 @@ TabContents* TabContents::CreateWithType(TabContentsType type, contents = new BrowserAboutHandler(profile, instance, NULL); break; case TAB_CONTENTS_DEBUGGER: - contents = new DebuggerContents(profile, instance); - break; + case TAB_CONTENTS_NEW_TAB_UI: case TAB_CONTENTS_DOM_UI: contents = new DOMUIContents(profile, instance, NULL); break; diff --git a/chrome/browser/tabs/tab_strip_model_unittest.cc b/chrome/browser/tabs/tab_strip_model_unittest.cc index 1f5e8e0..f8c1ed2 100644 --- a/chrome/browser/tabs/tab_strip_model_unittest.cc +++ b/chrome/browser/tabs/tab_strip_model_unittest.cc @@ -30,7 +30,7 @@ class TabStripDummyDelegate : public TabStripModelDelegate { virtual ~TabStripDummyDelegate() {} // Overridden from TabStripModelDelegate: - virtual GURL GetBlankTabURL() const { return NewTabUIURL(); } + virtual GURL GetBlankTabURL() const { return NewTabUI::GetBaseURL(); } virtual void CreateNewStripWithContents(TabContents* contents, const gfx::Rect& window_bounds, const DockInfo& dock_info) {} @@ -42,7 +42,7 @@ class TabStripDummyDelegate : public TabStripModelDelegate { PageTransition::Type transition, bool defer_load, SiteInstance* instance) const { - if (url == NewTabUIURL()) + if (url == NewTabUI::GetBaseURL()) return dummy_contents_; return NULL; } diff --git a/chrome/browser/views/download_shelf_view.cc b/chrome/browser/views/download_shelf_view.cc index b3bacde..ffcb3cd 100644 --- a/chrome/browser/views/download_shelf_view.cc +++ b/chrome/browser/views/download_shelf_view.cc @@ -265,7 +265,7 @@ void DownloadShelfView::LinkActivated(views::Link* source, int event_flags) { NavigationController* controller = tab_contents_->controller(); Browser* browser = Browser::GetBrowserForController(controller, &index); DCHECK(browser); - browser->ShowNativeUITab(DownloadTabUI::GetURL()); + browser->ShowDownloadsTab(); } void DownloadShelfView::ButtonPressed(views::BaseButton* button) { diff --git a/chrome/browser/views/options/general_page_view.cc b/chrome/browser/views/options/general_page_view.cc index 2d66925..c614950 100644 --- a/chrome/browser/views/options/general_page_view.cc +++ b/chrome/browser/views/options/general_page_view.cc @@ -22,6 +22,7 @@ #include "chrome/browser/views/keyword_editor_view.h" #include "chrome/browser/views/options/options_group_view.h" #include "chrome/browser/views/standard_layout.h" +#include "chrome/browser/dom_ui/new_tab_ui.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/l10n_util.h" #include "chrome/common/pref_names.h" @@ -45,7 +46,7 @@ static const SkColor kNotDefaultBrowserLabelColor = SkColorSetRGB(135, 0, 0); namespace { std::wstring GetNewTabUIURLString() { - return UTF8ToWide(NewTabUIURL().spec()); + return UTF8ToWide(NewTabUI::GetBaseURL().spec()); } } |