diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-04 23:55:06 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-04 23:55:06 +0000 |
commit | cd3d789910d9bbd81c2a08eee26bffc4ae10ab52 (patch) | |
tree | 2d640336dd883be4f375540ea6573ede6fd3e732 /chrome | |
parent | 90f6e2e8b787268630fcecddd7542e1bfb587ab3 (diff) | |
download | chromium_src-cd3d789910d9bbd81c2a08eee26bffc4ae10ab52.zip chromium_src-cd3d789910d9bbd81c2a08eee26bffc4ae10ab52.tar.gz chromium_src-cd3d789910d9bbd81c2a08eee26bffc4ae10ab52.tar.bz2 |
Clean up the browser about URL handler to not derive from WebContents. It is
instead integrated in the BrowserURLHandler for special schemes. This solves
a number of problems and cleans things up nicely.
Most of the functions were not necessary to have in the header file of the
browser about handler, so I made them local to the .cc file. I moved everything
around, but there was no change to any of the About...() functions.
This improves the about:memory page to not include the memory of the new tab
page it replaced. The entry for itself also has the proper title. This works
by using a meta refresh to the actual page, the the process transition no longer
happens at the same time as the about:memory page computation.
This also fixes problems with the about:network and about:ipc dialogs opening
blank pages and also re-opening the dialog when you close the browser.
Review URL: http://codereview.chromium.org/27238
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10941 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_about_handler.cc | 533 | ||||
-rw-r--r-- | chrome/browser/browser_about_handler.h | 79 | ||||
-rw-r--r-- | chrome/browser/browser_url_handler.cc | 23 | ||||
-rw-r--r-- | chrome/browser/memory_details.cc | 28 | ||||
-rw-r--r-- | chrome/browser/tab_contents/navigation_controller.cc | 17 | ||||
-rw-r--r-- | chrome/browser/tab_contents/navigation_entry.h | 6 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_factory.cc | 8 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_type.h | 2 | ||||
-rw-r--r-- | chrome/common/url_constants.cc | 6 | ||||
-rw-r--r-- | chrome/common/url_constants.h | 6 |
10 files changed, 355 insertions, 353 deletions
diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index 7f25a60..e8ba17d 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -20,8 +20,6 @@ #include "chrome/browser/dom_ui/chrome_url_data_manager.h" #include "chrome/browser/memory_details.h" #include "chrome/browser/net/dns_global.h" -#include "chrome/browser/profile.h" -#include "chrome/browser/profile_manager.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/common/jstemplate_builder.h" @@ -47,21 +45,39 @@ #include "chrome/browser/views/about_network_dialog.h" #endif -// The URL scheme used for the about ui. -static const char kAboutScheme[] = "about"; +namespace { // The paths used for the about pages. -static const char kCachePath[] = "cache"; -static const char kDnsPath[] = "dns"; -static const char kHistogramsPath[] = "histograms"; -static const char kObjectsPath[] = "objects"; -static const char kMemoryPath[] = "memory"; -static const char kPluginsPath[] = "plugins"; -static const char kStatsPath[] = "stats"; -static const char kVersionPath[] = "version"; -static const char kCreditsPath[] = "credits"; -static const char kTermsPath[] = "terms"; -static const char kLinuxSplash[] = "linux-splash"; +const char kCachePath[] = "cache"; +const char kDnsPath[] = "dns"; +const char kHistogramsPath[] = "histograms"; +const char kObjectsPath[] = "objects"; +const char kMemoryRedirectPath[] = "memory-redirect"; +const char kMemoryPath[] = "memory"; +const char kPluginsPath[] = "plugins"; +const char kStatsPath[] = "stats"; +const char kVersionPath[] = "version"; +const char kCreditsPath[] = "credits"; +const char kTermsPath[] = "terms"; +const char kLinuxSplash[] = "linux-splash"; + +// Points to the singleton AboutSource object, if any. +ChromeURLDataManager::DataSource* about_source = NULL; + +// When you type about:memory, it actually loads an intermediate URL that +// redirects you to the final page. This avoids the problem where typing +// "about:memory" on the new tab page or any other page where a process +// transition would occur to the about URL will cause some confusion. +// +// The problem is that during the processing of the memory page, there are two +// processes active, the original and the destination one. This can create the +// impression that we're using more resources than we actually are. This +// redirect solves the problem by eliminating the process transition during the +// time that about memory is being computed. +std::string GetAboutMemoryRedirectResponse() { + return "<meta http-equiv=\"refresh\" " + "content=\"0;chrome-ui://about/memory\">"; +} class AboutSource : public ChromeURLDataManager::DataSource { public: @@ -100,218 +116,42 @@ class AboutMemoryHandler : public MemoryDetails { AboutSource* source_; int request_id_; + DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); }; -AboutSource::AboutSource() - : DataSource(kAboutScheme, MessageLoop::current()) { -} - -AboutSource::~AboutSource() { -} - -void AboutSource::StartDataRequest(const std::string& path_raw, - int request_id) { - std::string path = path_raw; - std::string info; - if (path.find("/") != std::string::npos) { - size_t pos = path.find("/"); - info = path.substr(pos + 1, path.length() - (pos + 1)); - path = path.substr(0, pos); - } - path = StringToLowerASCII(path); - - std::string response; - if (path == kDnsPath) { - response = BrowserAboutHandler::AboutDns(); - } else if (path == kHistogramsPath) { - response = BrowserAboutHandler::AboutHistograms(info); - } else if (path == kMemoryPath) { - BrowserAboutHandler::AboutMemory(this, request_id); - return; - } else if (path == kObjectsPath) { - response = BrowserAboutHandler::AboutObjects(info); - } else if (path == kPluginsPath) { - response = BrowserAboutHandler::AboutPlugins(); - } else if (path == kStatsPath) { - response = BrowserAboutHandler::AboutStats(); - } else if (path == kVersionPath || path.empty()) { - response = BrowserAboutHandler::AboutVersion(); - } else if (path == kCreditsPath) { - response = BrowserAboutHandler::AboutCredits(); - } else if (path == kTermsPath) { - response = BrowserAboutHandler::AboutTerms(); - } -#if defined(OS_LINUX) - else if (path == kLinuxSplash) { - response = BrowserAboutHandler::AboutLinuxSplash(); - } -#endif - - FinishDataRequest(response, request_id); -} - -void AboutSource::FinishDataRequest(const std::string& response, - int request_id) { - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(response.size()); - std::copy(response.begin(), response.end(), html_bytes->data.begin()); - SendResponse(request_id, html_bytes); -} - -// This is the top-level URL handler for chrome-internal: URLs, and exposed in -// our header file. -bool BrowserAboutHandler::MaybeHandle(GURL* url, - TabContentsType* result_type) { - if (!url->SchemeIs(kAboutScheme)) - return false; - - // about:blank is special. Frames are allowed to access about:blank, - // but they are not allowed to access other types of about pages. - // Just ignore the about:blank and let the TAB_CONTENTS_WEB handle it. - if (StringToLowerASCII(url->path()) == "blank") { - return false; - } - - // We create an about:cache mapping to the view-cache: internal URL. - if (StringToLowerASCII(url->path()) == kCachePath) { - *url = GURL("view-cache:"); - *result_type = TAB_CONTENTS_WEB; - return true; - } - - if (LowerCaseEqualsASCII(url->path(), "network")) { -#if defined(OS_WIN) - // Run the dialog. This will re-use the existing one if it's already up. - AboutNetworkDialog::RunDialog(); -#else - NOTIMPLEMENTED(); - // TODO(port) Implement this. -#endif - - // Navigate the renderer to about:blank. This is kind of stupid but is the - // easiest thing to do in this situation without adding a lot of complexity - // for this developer-only feature. - *url = GURL("about:blank"); - return false; - } +// Individual about handlers --------------------------------------------------- -#ifdef IPC_MESSAGE_LOG_ENABLED - if (LowerCaseEqualsASCII(url->path(), "ipc")) { -#if defined(OS_WIN) - // Run the dialog. This will re-use the existing one if it's already up. - AboutIPCDialog::RunDialog(); -#else - NOTIMPLEMENTED(); - // TODO(port) Implement this. -#endif - *url = GURL("about:blank"); - return false; - } -#endif - - // There are a few about URLs that we hand over to the renderer. - // If the renderer wants them, let it have them. - if (AboutHandler::WillHandle(*url)) - return false; - - *result_type = TAB_CONTENTS_ABOUT_UI; - std::string about_url = "chrome-ui://about/"; - about_url.append(url->path()); - *url = GURL(about_url); - return true; -} - -BrowserAboutHandler::BrowserAboutHandler(Profile* profile, - SiteInstance* instance, - RenderViewHostFactory* render_view_factory) : - WebContents(profile, instance, render_view_factory, MSG_ROUTING_NONE, NULL) { - set_type(TAB_CONTENTS_ABOUT_UI); +std::string AboutCredits() { + static const std::string credits_html = + ResourceBundle::GetSharedInstance().GetDataResource( + IDR_CREDITS_HTML); - // We only need to register the AboutSource once and it is - // kept globally. There is currently no way to remove a data source. - static bool initialized = false; - if (!initialized) { - about_source_ = new AboutSource(); - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(&chrome_url_data_manager, - &ChromeURLDataManager::AddDataSource, - about_source_)); - initialized = true; - } + return credits_html; } -bool BrowserAboutHandler::SupportsURL(GURL* url) { - // Enable this tab contents to access javascript urls. - if (url->SchemeIs(chrome::kJavaScriptScheme)) - return true; - return WebContents::SupportsURL(url); +std::string AboutDns() { + std::string data; + chrome_browser_net::DnsPrefetchGetHtmlInfo(&data); + return data; } - -// static -std::string BrowserAboutHandler::AboutVersion() { - // Strings used in the JsTemplate file. - DictionaryValue localized_strings; - localized_strings.SetString(L"title", - l10n_util::GetString(IDS_ABOUT_VERSION_TITLE)); - scoped_ptr<FileVersionInfo> version_info( - FileVersionInfo::CreateFileVersionInfoForCurrentModule()); - if (version_info == NULL) { - DLOG(ERROR) << "Unable to create FileVersionInfo object"; - return std::string(); - } - - std::wstring webkit_version = UTF8ToWide(webkit_glue::GetWebKitVersion()); -#ifdef CHROME_V8 - const char* v8_vers = v8::V8::GetVersion(); - std::wstring js_version = UTF8ToWide(v8_vers); - std::wstring js_engine = L"V8"; -#else - std::wstring js_version = webkit_version; - std::wstring js_engine = L"JavaScriptCore"; -#endif - - localized_strings.SetString(L"name", - l10n_util::GetString(IDS_PRODUCT_NAME)); - localized_strings.SetString(L"version", version_info->file_version()); - localized_strings.SetString(L"js_engine", js_engine); - localized_strings.SetString(L"js_version", js_version); - localized_strings.SetString(L"webkit_version", webkit_version); - localized_strings.SetString(L"company", - l10n_util::GetString(IDS_ABOUT_VERSION_COMPANY_NAME)); - localized_strings.SetString(L"copyright", - l10n_util::GetString(IDS_ABOUT_VERSION_COPYRIGHT)); - localized_strings.SetString(L"cl", version_info->last_change()); - if (version_info->is_official_build()) { - localized_strings.SetString(L"official", - l10n_util::GetString(IDS_ABOUT_VERSION_OFFICIAL)); - } else { - localized_strings.SetString(L"official", - l10n_util::GetString(IDS_ABOUT_VERSION_UNOFFICIAL)); +std::string AboutHistograms(const std::string& query) { + std::string data; + for (RenderProcessHost::iterator it = RenderProcessHost::begin(); + it != RenderProcessHost::end(); ++it) { + it->second->Send(new ViewMsg_GetRendererHistograms()); } - localized_strings.SetString(L"useragent", - UTF8ToWide(webkit_glue::GetUserAgent(GURL()))); - - static const StringPiece version_html( - ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_ABOUT_VERSION_HTML)); - return jstemplate_builder::GetTemplateHtml( - version_html, &localized_strings, "t" /* template root node id */); -} - -// static -std::string BrowserAboutHandler::AboutCredits() { - static const std::string credits_html = - ResourceBundle::GetSharedInstance().GetDataResource( - IDR_CREDITS_HTML); + // TODO(raman): Delay page layout until we get respnoses + // back from renderers, and not have to use a fixed size delay. + PlatformThread::Sleep(1000); - return credits_html; + StatisticsRecorder::WriteHTMLGraph(query, &data); + return data; } -// static -std::string BrowserAboutHandler::AboutLinuxSplash() { +std::string AboutLinuxSplash() { static const std::string linux_splash_html = ResourceBundle::GetSharedInstance().GetDataResource( IDR_LINUX_SPLASH_HTML); @@ -319,17 +159,18 @@ std::string BrowserAboutHandler::AboutLinuxSplash() { return linux_splash_html; } -// static -std::string BrowserAboutHandler::AboutTerms() { - static const std::string terms_html = - ResourceBundle::GetSharedInstance().GetDataResource( - IDR_TERMS_HTML); +void AboutMemory(AboutSource* source, int request_id) { + // The AboutMemoryHandler cleans itself up. + new AboutMemoryHandler(source, request_id); +} - return terms_html; +std::string AboutObjects(const std::string& query) { + std::string data; + tracked_objects::ThreadData::WriteHTML(query, &data); + return data; } -// static -std::string BrowserAboutHandler::AboutPlugins() { +std::string AboutPlugins() { // Strings used in the JsTemplate file. DictionaryValue localized_strings; localized_strings.SetString(L"title", @@ -361,38 +202,7 @@ std::string BrowserAboutHandler::AboutPlugins() { plugins_html, &localized_strings, "t" /* template root node id */); } -// static -std::string BrowserAboutHandler::AboutHistograms(const std::string& query) { - std::string data; - for (RenderProcessHost::iterator it = RenderProcessHost::begin(); - it != RenderProcessHost::end(); ++it) { - it->second->Send(new ViewMsg_GetRendererHistograms()); - } - - // TODO(raman): Delay page layout until we get respnoses - // back from renderers, and not have to use a fixed size delay. - PlatformThread::Sleep(1000); - - StatisticsRecorder::WriteHTMLGraph(query, &data); - return data; -} - -// static -std::string BrowserAboutHandler::AboutObjects(const std::string& query) { - std::string data; - tracked_objects::ThreadData::WriteHTML(query, &data); - return data; -} - -// static -std::string BrowserAboutHandler::AboutDns() { - std::string data; - chrome_browser_net::DnsPrefetchGetHtmlInfo(&data); - return data; -} - -// static -std::string BrowserAboutHandler::AboutStats() { +std::string AboutStats() { // We keep the DictionaryValue tree live so that we can do delta // stats computations across runs. static DictionaryValue root; @@ -505,6 +315,136 @@ std::string BrowserAboutHandler::AboutStats() { return data; } +std::string AboutTerms() { + static const std::string terms_html = + ResourceBundle::GetSharedInstance().GetDataResource( + IDR_TERMS_HTML); + + return terms_html; +} + +std::string AboutVersion() { + // Strings used in the JsTemplate file. + DictionaryValue localized_strings; + localized_strings.SetString(L"title", + l10n_util::GetString(IDS_ABOUT_VERSION_TITLE)); + scoped_ptr<FileVersionInfo> version_info( + FileVersionInfo::CreateFileVersionInfoForCurrentModule()); + if (version_info == NULL) { + DLOG(ERROR) << "Unable to create FileVersionInfo object"; + return std::string(); + } + + std::wstring webkit_version = UTF8ToWide(webkit_glue::GetWebKitVersion()); +#ifdef CHROME_V8 + const char* v8_vers = v8::V8::GetVersion(); + std::wstring js_version = UTF8ToWide(v8_vers); + std::wstring js_engine = L"V8"; +#else + std::wstring js_version = webkit_version; + std::wstring js_engine = L"JavaScriptCore"; +#endif + + localized_strings.SetString(L"name", + l10n_util::GetString(IDS_PRODUCT_NAME)); + localized_strings.SetString(L"version", version_info->file_version()); + localized_strings.SetString(L"js_engine", js_engine); + localized_strings.SetString(L"js_version", js_version); + localized_strings.SetString(L"webkit_version", webkit_version); + localized_strings.SetString(L"company", + l10n_util::GetString(IDS_ABOUT_VERSION_COMPANY_NAME)); + localized_strings.SetString(L"copyright", + l10n_util::GetString(IDS_ABOUT_VERSION_COPYRIGHT)); + localized_strings.SetString(L"cl", version_info->last_change()); + if (version_info->is_official_build()) { + localized_strings.SetString(L"official", + l10n_util::GetString(IDS_ABOUT_VERSION_OFFICIAL)); + } else { + localized_strings.SetString(L"official", + l10n_util::GetString(IDS_ABOUT_VERSION_UNOFFICIAL)); + } + localized_strings.SetString(L"useragent", + UTF8ToWide(webkit_glue::GetUserAgent(GURL()))); + + static const StringPiece version_html( + ResourceBundle::GetSharedInstance().GetRawDataResource( + IDR_ABOUT_VERSION_HTML)); + + return jstemplate_builder::GetTemplateHtml( + version_html, &localized_strings, "t" /* template root node id */); +} + +// AboutSource ----------------------------------------------------------------- + +AboutSource::AboutSource() + : DataSource(chrome::kAboutScheme, MessageLoop::current()) { + // This should be a singleton. + DCHECK(!about_source); + about_source = this; + + // Add us to the global URL handler on the IO thread. + g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, + NewRunnableMethod(&chrome_url_data_manager, + &ChromeURLDataManager::AddDataSource, this)); +} + +AboutSource::~AboutSource() { + about_source = NULL; +} + +void AboutSource::StartDataRequest(const std::string& path_raw, + int request_id) { + std::string path = path_raw; + std::string info; + if (path.find("/") != std::string::npos) { + size_t pos = path.find("/"); + info = path.substr(pos + 1, path.length() - (pos + 1)); + path = path.substr(0, pos); + } + path = StringToLowerASCII(path); + + std::string response; + if (path == kDnsPath) { + response = AboutDns(); + } else if (path == kHistogramsPath) { + response = AboutHistograms(info); + } else if (path == kMemoryPath) { + AboutMemory(this, request_id); + return; + } else if (path == kMemoryRedirectPath) { + response = GetAboutMemoryRedirectResponse(); + } else if (path == kObjectsPath) { + response = AboutObjects(info); + } else if (path == kPluginsPath) { + response = AboutPlugins(); + } else if (path == kStatsPath) { + response = AboutStats(); + } else if (path == kVersionPath || path.empty()) { + response = AboutVersion(); + } else if (path == kCreditsPath) { + response = AboutCredits(); + } else if (path == kTermsPath) { + response = AboutTerms(); + } +#if defined(OS_LINUX) + else if (path == kLinuxSplash) { + response = AboutLinuxSplash(); + } +#endif + + FinishDataRequest(response, request_id); +} + +void AboutSource::FinishDataRequest(const std::string& response, + int request_id) { + scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); + html_bytes->data.resize(response.size()); + std::copy(response.begin(), response.end(), html_bytes->data.begin()); + SendResponse(request_id, html_bytes); +} + +// AboutMemoryHandler ---------------------------------------------------------- + AboutMemoryHandler::AboutMemoryHandler(AboutSource* source, int request_id) : source_(source), request_id_(request_id) { @@ -515,7 +455,7 @@ AboutMemoryHandler::AboutMemoryHandler(AboutSource* source, int request_id) // to a DictionaryValue. Fills ws_usage and comm_usage so that the objects // can be used in caller's scope (e.g for appending to a net total). void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data, - ProcessMemoryInformation* info) { + ProcessMemoryInformation* info) { DCHECK(data && info); // Bind metrics to dictionary. @@ -629,12 +569,85 @@ void AboutMemoryHandler::OnDetailsAvailable() { std::string template_html = jstemplate_builder::GetTemplateHtml( memory_html, &root, "t" /* template root node id */); - AboutSource* about_source = static_cast<AboutSource*>(source_); - about_source->FinishDataRequest(template_html, request_id_); + AboutSource* src = static_cast<AboutSource*>(source_); + src->FinishDataRequest(template_html, request_id_); } -// static -void BrowserAboutHandler::AboutMemory(AboutSource* source, int request_id) { - // The AboutMemoryHandler cleans itself up. - new AboutMemoryHandler(source, request_id); +} // namespace + +// ----------------------------------------------------------------------------- + +bool WillHandleBrowserAboutURL(GURL* url, TabContentsType* type) { + // We only handle about: schemes. + if (!url->SchemeIs(chrome::kAboutScheme)) + return false; + + // about:blank is special. Frames are allowed to access about:blank, + // but they are not allowed to access other types of about pages. + // Just ignore the about:blank and let the TAB_CONTENTS_WEB handle it. + if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutBlankURL)) + return false; + + // Handle rewriting view-cache URLs. This allows us to load about:cache. + if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutCacheURL)) { + // Create an mapping from about:cache to the view-cache: internal URL. + *url = GURL(std::string(chrome::kViewCacheScheme) + ":"); + *type = TAB_CONTENTS_WEB; + return true; + } + + // There are a few about: URLs that we hand over to the renderer. If the + // renderer wants them, don't do any rewriting. + if (AboutHandler::WillHandle(*url)) + return false; + + // Anything else requires our special handler, make sure its initialized. + // We only need to register the AboutSource once and it is kept globally. + // There is currently no way to remove a data source. + static bool initialized = false; + if (!initialized) { + about_source = new AboutSource(); + initialized = true; + } + + // Special case about:memory to go through a redirect before ending up on + // the final page. See GetAboutMemoryRedirectResponse above for why. + if (LowerCaseEqualsASCII(url->path(), kMemoryPath)) { + *url = GURL("chrome-ui://about/memory-redirect"); + *type = TAB_CONTENTS_WEB; + return true; + } + + // Rewrite the about URL to use chrome-ui. WebKit treats all about URLS the + // same (blank page), so if we want to display content, we need another + // scheme. + std::string about_url = "chrome-ui://about/"; + about_url.append(url->path()); + *url = GURL(about_url); + *type = TAB_CONTENTS_WEB; + return true; +} + +// This function gets called with the fixed-up chrome-ui URLs, so we have to +// compare against those instead of "about:blah". +bool HandleNonNavigationAboutURL(const GURL& url) { +#if defined(OS_WIN) + if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUINetworkURL)) { + // Run the dialog. This will re-use the existing one if it's already up. + AboutNetworkDialog::RunDialog(); + return true; + } + +#ifdef IPC_MESSAGE_LOG_ENABLED + if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) { + // Run the dialog. This will re-use the existing one if it's already up. + AboutIPCDialog::RunDialog(); + return true; + } +#endif + +#else + // TODO(port) Implement this. +#endif + return false; } diff --git a/chrome/browser/browser_about_handler.h b/chrome/browser/browser_about_handler.h index 21ffb27..abad2aa1 100644 --- a/chrome/browser/browser_about_handler.h +++ b/chrome/browser/browser_about_handler.h @@ -7,76 +7,21 @@ #ifndef CHROME_BROWSER_BROWSER_ABOUT_HANDLER_H_ #define CHROME_BROWSER_BROWSER_ABOUT_HANDLER_H_ -#include <string> - -#include "base/basictypes.h" #include "chrome/browser/tab_contents/tab_contents_type.h" -#include "chrome/browser/tab_contents/web_contents.h" -#include "chrome/browser/dom_ui/chrome_url_data_manager.h" -class AboutSource; -class DictionaryValue; class GURL; -class ListValue; -class Profile; -class RenderProcessHost; -class RenderViewHostFactory; -class SiteInstance; - -class BrowserAboutHandler : public WebContents { - public: - BrowserAboutHandler(Profile* profile, - SiteInstance* instance, - RenderViewHostFactory* render_view_factory); - virtual ~BrowserAboutHandler() {} - - // We don't want a favicon on the about pages. - virtual bool ShouldDisplayFavIcon() { return false; } - // Enable javascript urls for the about pages. - virtual bool SupportsURL(GURL* url); - - // If |url| is a known "about:" URL, this method handles it - // and sets |url| to an alternate URL indicating the real content to load. - // (If it's not a URL that the function can handle, it's a no-op and returns - // false.) - static bool MaybeHandle(GURL* url, TabContentsType* type); - - // Renders a special page for "about:" which displays version information. - static std::string AboutVersion(); - - // Renders a special page for about:plugins. - static std::string AboutPlugins(); - - // Renders a special page for about:histograms. - static std::string AboutHistograms(const std::string& query); - - // Renders a special page about:objects (about tracked objects such as Tasks). - static std::string AboutObjects(const std::string& query); - - // Renders a special page for about:dns. - static std::string AboutDns(); - - // Renders a special page for about:stats. - static std::string AboutStats(); - - // Renders a special page for "about:credits" which displays our - // acknowledgements and legal information for code we depend on. - static std::string AboutCredits(); - - // Renders a special page for "about:terms" which displays our - // terms and conditions. - static std::string AboutTerms(); - - // Renders a special page for about:memory which displays - // information about current state. - static void AboutMemory(AboutSource*, int request_id); - - // This displays the Linux splash screen for development releases. - static std::string AboutLinuxSplash(); - private: - ChromeURLDataManager::DataSource* about_source_; - DISALLOW_COPY_AND_ASSIGN(BrowserAboutHandler); -}; +// Decides whether the given URL will be handled by the browser about handler +// and returns true if so. On true, it may also modify the given URL to be the +// final form (we fix up most "about:" URLs to be "chrome-ui:" because WebKit +// handles all "about:" URLs as "about:blank. +// +// This is used by BrowserURLHandler. +bool WillHandleBrowserAboutURL(GURL* url, TabContentsType* type); + +// We have a few magic commands that don't cause navigations, but rather pop up +// dialogs. This function handles those cases, and returns true if so. In this +// case, normal tab navigation should be skipped. +bool HandleNonNavigationAboutURL(const GURL& url); #endif // CHROME_BROWSER_BROWSER_ABOUT_HANDLER_H_ diff --git a/chrome/browser/browser_url_handler.cc b/chrome/browser/browser_url_handler.cc index 98bdaa0..88cb0e2 100644 --- a/chrome/browser/browser_url_handler.cc +++ b/chrome/browser/browser_url_handler.cc @@ -4,8 +4,21 @@ #include "chrome/browser/browser_url_handler.h" +#include "base/string_util.h" #include "chrome/browser/browser_about_handler.h" #include "chrome/browser/dom_ui/dom_ui_contents.h" +#include "chrome/common/url_constants.h" + +// Handles rewriting view-source URLs for what we'll actually load. +static bool HandleViewSource(GURL* url, TabContentsType* type) { + if (url->SchemeIs(chrome::kViewSourceScheme)) { + // Load the inner URL instead. + *url = GURL(url->path()); + *type = TAB_CONTENTS_WEB; + return true; + } + return false; +} std::vector<BrowserURLHandler::URLHandler> BrowserURLHandler::url_handlers_; @@ -14,11 +27,10 @@ void BrowserURLHandler::InitURLHandlers() { if (!url_handlers_.empty()) return; - // Here is where we initialize the global list of handlers for special URLs. - // about:* - url_handlers_.push_back(&BrowserAboutHandler::MaybeHandle); - // chrome-ui:* - url_handlers_.push_back(&DOMUIContentsCanHandleURL); + // Add the default URL handlers. + url_handlers_.push_back(&WillHandleBrowserAboutURL); // about: + url_handlers_.push_back(&DOMUIContentsCanHandleURL); // chrome-ui: + url_handlers_.push_back(&HandleViewSource); // view-source: } // static @@ -31,4 +43,3 @@ bool BrowserURLHandler::HandleBrowserURL(GURL* url, TabContentsType* type) { } return false; } - diff --git a/chrome/browser/memory_details.cc b/chrome/browser/memory_details.cc index b60a16c..ba27f89 100644 --- a/chrome/browser/memory_details.cc +++ b/chrome/browser/memory_details.cc @@ -10,8 +10,10 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/renderer_host/render_process_host.h" +#include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/web_contents.h" #include "chrome/common/child_process_host.h" +#include "chrome/common/url_constants.h" class RenderViewHostDelegate; @@ -180,8 +182,7 @@ void MemoryDetails::CollectChildInfoOnUIThread() { // Check if it's a renderer, if so get the list of page titles in it and // check if it's a diagnostics-related process. We skip all diagnostics // pages (e.g. "about:xxx" URLs). Iterate the RenderProcessHosts to find - // the tab contents. If it is of type TAB_CONTENTS_ABOUT_UI, mark the - // process as diagnostics related. + // the tab contents. RenderProcessHost::iterator renderer_iter; for (renderer_iter = RenderProcessHost::begin(); renderer_iter != RenderProcessHost::end(); ++renderer_iter) { @@ -217,7 +218,28 @@ void MemoryDetails::CollectChildInfoOnUIThread() { if (!title.length()) title = L"Untitled"; process.titles.push_back(title); - if (contents->type() == TAB_CONTENTS_ABOUT_UI) + + // We need to check the pending entry as well as the pending entry to + // see if it's an about:memory URL (we don't want to count these in the + // total memory usage of the browser). + // + // When we reach here, about:memory will be the pending entry since we + // haven't responded with any data such that it would be committed. If + // you have another about:memory tab open (which would be committed), + // we don't want to count it either, so we also check the last committed + // entry. + // + // Either the pending or last committed entries can be NULL. + const NavigationEntry* pending_entry = NULL; + //contents->controller()->GetPendingEntry(); + const NavigationEntry* last_committed_entry = + contents->controller()->GetLastCommittedEntry(); + if ((last_committed_entry && + LowerCaseEqualsASCII(last_committed_entry->display_url().spec(), + chrome::kAboutMemoryURL)) || + (pending_entry && + LowerCaseEqualsASCII(pending_entry->display_url().spec(), + chrome::kAboutMemoryURL))) process.is_diagnostics = true; } } diff --git a/chrome/browser/tab_contents/navigation_controller.cc b/chrome/browser/tab_contents/navigation_controller.cc index 374b1804..850a865 100644 --- a/chrome/browser/tab_contents/navigation_controller.cc +++ b/chrome/browser/tab_contents/navigation_controller.cc @@ -7,6 +7,7 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/string_util.h" +#include "chrome/browser/browser_about_handler.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/dom_ui/dom_ui_host.h" #include "chrome/browser/sessions/session_types.h" @@ -55,7 +56,6 @@ void SetContentStateIfEmpty(NavigationEntry* entry) { (entry->tab_type() == TAB_CONTENTS_WEB || entry->tab_type() == TAB_CONTENTS_NEW_TAB_UI || entry->tab_type() == TAB_CONTENTS_DOM_UI || - entry->tab_type() == TAB_CONTENTS_ABOUT_UI || entry->tab_type() == TAB_CONTENTS_HTML_DIALOG || entry->IsViewSourceMode())) { entry->set_content_state( @@ -247,6 +247,11 @@ NavigationEntry* NavigationController::GetEntryWithPageID( } void NavigationController::LoadEntry(NavigationEntry* entry) { + // Handle non-navigational URLs that popup dialogs and such, these should not + // actually navigate. + if (HandleNonNavigationAboutURL(entry->url())) + return; + // When navigating to a new page, we don't know for sure if we will actually // end up leaving the current page. The new page load could for example // result in a download or a 'no content' response (e.g., a mailto: URL). @@ -463,17 +468,15 @@ NavigationEntry* NavigationController::CreateNavigationEntry( // If the active contents supports |url|, use it. // Note: in both cases, we give TabContents a chance to rewrite the URL. + // + // TODO(brettw): The BrowserURLHandler::HandleBrowserURL call should just be + // moved here from inside TypeForURL once the tab contents types are removed. TabContents* active = active_contents(); if (active && active->SupportsURL(&real_url)) type = active->type(); else type = TabContents::TypeForURL(&real_url); - - if (url.SchemeIs(chrome::kViewSourceScheme)) { - // Load the inner URL instead, setting the original URL as the "display". - real_url = GURL(url.path()); - } - + NavigationEntry* entry = new NavigationEntry(type, NULL, -1, real_url, referrer, string16(), transition); diff --git a/chrome/browser/tab_contents/navigation_entry.h b/chrome/browser/tab_contents/navigation_entry.h index 9cad672..55ed4f3 100644 --- a/chrome/browser/tab_contents/navigation_entry.h +++ b/chrome/browser/tab_contents/navigation_entry.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_NAVIGATION_ENTRY_H_ -#define CHROME_BROWSER_NAVIGATION_ENTRY_H_ +#ifndef CHROME_BROWSER_TAB_CONTENTS_NAVIGATION_ENTRY_H_ +#define CHROME_BROWSER_TAB_CONTENTS_NAVIGATION_ENTRY_H_ #include "base/basictypes.h" #include "base/scoped_ptr.h" @@ -407,4 +407,4 @@ class NavigationEntry { // Copy and assignment is explicitly allowed for this class. }; -#endif // CHROME_BROWSER_NAVIGATION_ENTRY_H_ +#endif // CHROME_BROWSER_TAB_CONTENTS_NAVIGATION_ENTRY_H_ diff --git a/chrome/browser/tab_contents/tab_contents_factory.cc b/chrome/browser/tab_contents/tab_contents_factory.cc index 0226b4f..01db2d1 100644 --- a/chrome/browser/tab_contents/tab_contents_factory.cc +++ b/chrome/browser/tab_contents/tab_contents_factory.cc @@ -47,9 +47,6 @@ TabContents* TabContents::CreateWithType(TabContentsType type, case TAB_CONTENTS_WEB: contents = new WebContents(profile, instance, NULL, MSG_ROUTING_NONE, NULL); break; - case TAB_CONTENTS_ABOUT_UI: - contents = new BrowserAboutHandler(profile, instance, NULL); - break; // TODO(port): remove this platform define, either by porting the tab contents // types or removing them completely. #if defined(OS_WIN) @@ -82,6 +79,8 @@ TabContents* TabContents::CreateWithType(TabContentsType type, // static TabContentsType TabContents::TypeForURL(GURL* url) { + // The BrowserURLHandler::HandleBrowserURL call should just be inside the + // NavigationController once this class is deleted. DCHECK(url); if (g_extra_types) { TabContentsFactoryMap::const_iterator it = g_extra_types->begin(); @@ -109,8 +108,7 @@ TabContentsType TabContents::TypeForURL(GURL* url) { return TAB_CONTENTS_DOM_UI; #elif defined(OS_POSIX) TabContentsType type(TAB_CONTENTS_UNKNOWN_TYPE); - if (BrowserURLHandler::HandleBrowserURL(url, &type) && - type == TAB_CONTENTS_ABOUT_UI) { + if (BrowserURLHandler::HandleBrowserURL(url, &type)) { return type; } if (url->SchemeIs(DOMUIContents::GetScheme().c_str())) diff --git a/chrome/browser/tab_contents/tab_contents_type.h b/chrome/browser/tab_contents/tab_contents_type.h index 9955258..517e5a9 100644 --- a/chrome/browser/tab_contents/tab_contents_type.h +++ b/chrome/browser/tab_contents/tab_contents_type.h @@ -12,11 +12,9 @@ enum TabContentsType { TAB_CONTENTS_UNKNOWN_TYPE = 0, TAB_CONTENTS_WEB, - TAB_CONTENTS_DOWNLOAD_VIEW, TAB_CONTENTS_CHROME_VIEW_CONTENTS, TAB_CONTENTS_NEW_TAB_UI, TAB_CONTENTS_HTML_DIALOG, - TAB_CONTENTS_ABOUT_UI, TAB_CONTENTS_DEBUGGER, TAB_CONTENTS_DOM_UI, TAB_CONTENTS_NUM_TYPES diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc index 3754dab..f5db717 100644 --- a/chrome/common/url_constants.cc +++ b/chrome/common/url_constants.cc @@ -18,10 +18,16 @@ const char kHttpsScheme[] = "https"; const char kJavaScriptScheme[] = "javascript"; const char kMailToScheme[] = "mailto"; const char kUserScriptScheme[] = "chrome-user-script"; +const char kViewCacheScheme[] = "view-cache"; const char kViewSourceScheme[] = "view-source"; const char kStandardSchemeSeparator[] = "://"; const char kAboutBlankURL[] = "about:blank"; +const char kAboutCacheURL[] = "about:cache"; +const char kAboutMemoryURL[] = "about:memory"; + +const char kChromeUIIPCURL[] = "chrome-ui://about/ipc"; +const char kChromeUINetworkURL[] = "chrome-ui://about/network"; } // namespace chrome diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h index 21808ce..6761663 100644 --- a/chrome/common/url_constants.h +++ b/chrome/common/url_constants.h @@ -22,6 +22,7 @@ extern const char kHttpsScheme[]; extern const char kJavaScriptScheme[]; extern const char kMailToScheme[]; extern const char kUserScriptScheme[]; +extern const char kViewCacheScheme[]; extern const char kViewSourceScheme[]; // Used to separate a standard scheme and the hostname: "://". @@ -29,6 +30,11 @@ extern const char kStandardSchemeSeparator[]; // About URLs (including schmes). extern const char kAboutBlankURL[]; +extern const char kAboutCacheURL[]; +extern const char kAboutMemoryURL[]; + +extern const char kChromeUIIPCURL[]; +extern const char kChromeUINetworkURL[]; } // namespace chrome |