Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2649)

Unified Diff: chrome/browser/ui/webui/about_ui.cc

Issue 8623001: Move remaining about: handlers to webUI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/about_ui.h ('k') | chrome/browser/ui/webui/chrome_web_ui_factory.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/about_ui.cc
===================================================================
--- chrome/browser/ui/webui/about_ui.cc (revision 110966)
+++ chrome/browser/ui/webui/about_ui.cc (working copy)
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/browser_about_handler.h"
+#include "chrome/browser/ui/webui/about_ui.h"
#include <algorithm>
#include <string>
@@ -27,6 +27,7 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/about_flags.h"
+#include "chrome/browser/browser_about_handler.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/memory_details.h"
@@ -49,6 +50,7 @@
#include "content/browser/plugin_service.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/sensors/sensors_provider.h"
+#include "content/browser/tab_contents/tab_contents.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/content_client.h"
@@ -90,145 +92,14 @@
using base::TimeDelta;
using content::BrowserThread;
-#if defined(USE_TCMALLOC)
-// static
-AboutTcmallocOutputs* AboutTcmallocOutputs::GetInstance() {
- return Singleton<AboutTcmallocOutputs>::get();
-}
-
-AboutTcmallocOutputs::AboutTcmallocOutputs() {}
-
-AboutTcmallocOutputs::~AboutTcmallocOutputs() {}
-
-// Glue between the callback task and the method in the singleton.
-void AboutTcmallocRendererCallback(base::ProcessId pid,
- const std::string& output) {
- AboutTcmallocOutputs::GetInstance()->RendererCallback(pid, output);
-}
-#endif
-
namespace {
-// Add paths here to be included in chrome://chrome-urls (about:about).
-// These paths will also be suggested by BuiltinProvider.
-const char* const kChromePaths[] = {
- chrome::kChromeUIAppCacheInternalsHost,
- chrome::kChromeUIBlobInternalsHost,
- chrome::kChromeUIBookmarksHost,
- chrome::kChromeUICacheHost,
- chrome::kChromeUIChromeURLsHost,
- chrome::kChromeUICrashesHost,
- chrome::kChromeUICreditsHost,
- chrome::kChromeUIDNSHost,
- chrome::kChromeUIDownloadsHost,
- chrome::kChromeUIExtensionsHost,
- chrome::kChromeUIFlagsHost,
- chrome::kChromeUIFlashHost,
- chrome::kChromeUIGpuInternalsHost,
- chrome::kChromeUIHistogramsHost,
- chrome::kChromeUIHistoryHost,
- chrome::kChromeUIIPCHost,
- chrome::kChromeUIMediaInternalsHost,
- chrome::kChromeUIMemoryHost,
- chrome::kChromeUINetInternalsHost,
- chrome::kChromeUINetworkViewCacheHost,
- chrome::kChromeUINewTabHost,
- chrome::kChromeUIPluginsHost,
- chrome::kChromeUIPrintHost,
- chrome::kChromeUIProfilerHost,
- chrome::kChromeUIQuotaInternalsHost,
- chrome::kChromeUISessionsHost,
- chrome::kChromeUISettingsHost,
- chrome::kChromeUIStatsHost,
- chrome::kChromeUISyncInternalsHost,
- chrome::kChromeUITaskManagerHost,
- chrome::kChromeUITCMallocHost,
- chrome::kChromeUITermsHost,
- chrome::kChromeUITracingHost,
- chrome::kChromeUIVersionHost,
- chrome::kChromeUIWorkersHost,
-#if defined(OS_WIN)
- chrome::kChromeUIConflictsHost,
-#endif
-#if defined(OS_LINUX) || defined(OS_OPENBSD)
- chrome::kChromeUILinuxProxyConfigHost,
- chrome::kChromeUISandboxHost,
-#endif
-#if defined(OS_CHROMEOS)
- chrome::kChromeUIActiveDownloadsHost,
- chrome::kChromeUIChooseMobileNetworkHost,
- chrome::kChromeUICryptohomeHost,
- chrome::kChromeUIDiscardsHost,
- chrome::kChromeUIImageBurnerHost,
- chrome::kChromeUIKeyboardOverlayHost,
- chrome::kChromeUILoginHost,
- chrome::kChromeUINetworkHost,
- chrome::kChromeUIOobeHost,
- chrome::kChromeUIOSCreditsHost,
- chrome::kChromeUIProxySettingsHost,
- chrome::kChromeUISystemInfoHost,
-#endif
-};
-
-// AboutSource handles these chrome:// paths.
-const char* const kAboutSourceNames[] = {
- chrome::kChromeUIChromeURLsHost,
- chrome::kChromeUICreditsHost,
- chrome::kChromeUIDNSHost,
- chrome::kChromeUIHistogramsHost,
- chrome::kChromeUIMemoryHost,
- chrome::kChromeUIMemoryRedirectHost,
- chrome::kChromeUIStatsHost,
- chrome::kChromeUITaskManagerHost,
- chrome::kChromeUITermsHost,
- chrome::kChromeUIVersionHost,
-#if defined(USE_TCMALLOC)
- chrome::kChromeUITCMallocHost,
-#endif
-#if defined(OS_LINUX) || defined(OS_OPENBSD)
- chrome::kChromeUILinuxProxyConfigHost,
- chrome::kChromeUISandboxHost,
-#endif
-#if defined(OS_CHROMEOS)
- chrome::kChromeUICryptohomeHost,
- chrome::kChromeUIDiscardsHost,
- chrome::kChromeUINetworkHost,
- chrome::kChromeUIOSCreditsHost,
-#endif
-};
-
const char kCreditsJsPath[] = "credits.js";
const char kMemoryJsPath[] = "memory.js";
const char kStatsJsPath[] = "stats.js";
const char kStringsJsPath[] = "strings.js";
const char kVersionJsPath[] = "version.js";
-class AboutSource : public ChromeURLDataManager::DataSource {
- public:
- // Construct a data source for the specified |source_name|.
- AboutSource(const std::string& source_name, Profile* profile);
-
- // Called when the network layer has requested a resource underneath
- // the path we registered.
- virtual void StartDataRequest(const std::string& path,
- bool is_incognito,
- int request_id) OVERRIDE;
-
- virtual std::string GetMimeType(const std::string& path) const OVERRIDE;
-
- // Send the response data.
- void FinishDataRequest(const std::string& html, int request_id);
-
- Profile* profile() { return profile_; }
-
- private:
- virtual ~AboutSource();
-
- Profile* profile_;
-
- DISALLOW_COPY_AND_ASSIGN(AboutSource);
-};
-
// When you type about:memory, it actually loads this 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
@@ -240,7 +111,6 @@
// redirect solves the problem by eliminating the process transition during the
// time that about memory is being computed.
std::string GetAboutMemoryRedirectResponse(Profile* profile) {
- InitializeAboutDataSource(chrome::kChromeUIMemoryRedirectHost, profile);
return StringPrintf("<meta http-equiv=\"refresh\" content=\"0;%s\">",
chrome::kChromeUIMemoryRedirectURL);
}
@@ -250,7 +120,7 @@
// its |StartFetch()| method.
class AboutMemoryHandler : public MemoryDetails {
public:
- AboutMemoryHandler(AboutSource* source, int request_id)
+ AboutMemoryHandler(AboutUIHTMLSource* source, int request_id)
: source_(source),
request_id_(request_id) {
}
@@ -264,7 +134,7 @@
ProcessMemoryInformation* info);
void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info);
- scoped_refptr<AboutSource> source_;
+ scoped_refptr<AboutUIHTMLSource> source_;
int request_id_;
DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler);
@@ -274,10 +144,10 @@
// ChromeOSAboutVersionHandler is responsible for loading the Chrome OS
// version.
// ChromeOSAboutVersionHandler handles deleting itself once the version has
-// been obtained and AboutSource notified.
+// been obtained and AboutUIHTMLSource notified.
class ChromeOSAboutVersionHandler {
public:
- ChromeOSAboutVersionHandler(AboutSource* source, int request_id);
+ ChromeOSAboutVersionHandler(AboutUIHTMLSource* source, int request_id);
// Callback from chromeos::VersionLoader giving the version.
void OnVersion(chromeos::VersionLoader::Handle handle,
@@ -285,7 +155,7 @@
private:
// Where the results are fed to.
- scoped_refptr<AboutSource> source_;
+ scoped_refptr<AboutUIHTMLSource> source_;
// ID identifying the request.
int request_id_;
@@ -302,7 +172,7 @@
class ChromeOSTermsHandler
: public base::RefCountedThreadSafe<ChromeOSTermsHandler> {
public:
- static void Start(AboutSource* source,
+ static void Start(AboutUIHTMLSource* source,
const std::string& path,
int request_id) {
scoped_refptr<ChromeOSTermsHandler> handler(
@@ -311,7 +181,7 @@
}
private:
- ChromeOSTermsHandler(AboutSource* source,
+ ChromeOSTermsHandler(AboutUIHTMLSource* source,
const std::string& path,
int request_id)
: source_(source),
@@ -371,7 +241,7 @@
}
// Where the results are fed to.
- scoped_refptr<AboutSource> source_;
+ scoped_refptr<AboutUIHTMLSource> source_;
// Path in the URL.
std::string path_;
@@ -746,14 +616,14 @@
// the DNS information.
class AboutDnsHandler : public base::RefCountedThreadSafe<AboutDnsHandler> {
public:
- static void Start(AboutSource* source, int request_id) {
+ static void Start(AboutUIHTMLSource* source, int request_id) {
scoped_refptr<AboutDnsHandler> handler(
new AboutDnsHandler(source, request_id));
handler->StartOnUIThread();
}
private:
- AboutDnsHandler(AboutSource* source, int request_id)
+ AboutDnsHandler(AboutUIHTMLSource* source, int request_id)
: source_(source),
request_id_(request_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -789,7 +659,7 @@
}
// Where the results are fed to.
- scoped_refptr<AboutSource> source_;
+ scoped_refptr<AboutUIHTMLSource> source_;
// ID identifying the request.
int request_id_;
@@ -870,10 +740,11 @@
return data;
}
-void AboutMemory(const std::string& path, AboutSource* source, int request_id) {
+void AboutMemory(const std::string& path, AboutUIHTMLSource* source,
+ int request_id) {
if (path == kStringsJsPath) {
- // The AboutMemoryHandler cleans itself up, but |StartFetch()| will want the
- // refcount to be greater than 0.
+ // The AboutMemoryHandler cleans itself up, but |StartFetch()| will want
+ // the refcount to be greater than 0.
scoped_refptr<AboutMemoryHandler>
handler(new AboutMemoryHandler(source, request_id));
handler->StartFetch();
@@ -1229,7 +1100,7 @@
}
// Used as a callback for PluginService::GetPlugins().
-void HandleAboutVersionStrings(AboutSource* source,
+void HandleAboutVersionStrings(AboutUIHTMLSource* source,
int request_id,
const std::vector<webkit::WebPluginInfo>&) {
#if defined(OS_CHROMEOS)
@@ -1277,8 +1148,8 @@
BindProcessMetrics(child, info);
std::string child_label(
- ChildProcessInfo::GetFullTypeNameInEnglish(info->type,
- info->renderer_type));
+ ProcessMemoryInformation::GetFullTypeNameInEnglish(info->type,
+ info->renderer_type));
if (info->is_diagnostics)
child_label.append(" (diagnostics)");
child->SetString("child_name", child_label);
@@ -1373,7 +1244,7 @@
// ChromeOSAboutVersionHandler -----------------------------------------------
ChromeOSAboutVersionHandler::ChromeOSAboutVersionHandler(
- AboutSource* source,
+ AboutUIHTMLSource* source,
int request_id)
: source_(source),
request_id_(request_id) {
@@ -1400,17 +1271,18 @@
} // namespace
-// AboutSource -----------------------------------------------------------------
+// AboutUIHTMLSource ----------------------------------------------------------
-AboutSource::AboutSource(const std::string& source_name, Profile* profile)
+AboutUIHTMLSource::AboutUIHTMLSource(const std::string& source_name,
+ Profile* profile)
: DataSource(source_name, MessageLoop::current()),
profile_(profile) {
}
-AboutSource::~AboutSource() {
+AboutUIHTMLSource::~AboutUIHTMLSource() {
}
-void AboutSource::StartDataRequest(const std::string& path,
+void AboutUIHTMLSource::StartDataRequest(const std::string& path,
bool is_incognito,
int request_id) {
std::string response;
@@ -1483,12 +1355,13 @@
FinishDataRequest(response, request_id);
}
-void AboutSource::FinishDataRequest(const std::string& html, int request_id) {
+void AboutUIHTMLSource::FinishDataRequest(const std::string& html,
+ int request_id) {
std::string html_copy(html);
SendResponse(request_id, base::RefCountedString::TakeString(&html_copy));
}
-std::string AboutSource::GetMimeType(const std::string& path) const {
+std::string AboutUIHTMLSource::GetMimeType(const std::string& path) const {
if (path == kCreditsJsPath ||
path == kStatsJsPath ||
path == kStringsJsPath ||
@@ -1499,128 +1372,11 @@
return "text/html";
}
-// -----------------------------------------------------------------------------
-
-void InitializeAboutDataSource(const std::string& name,
- content::BrowserContext* browser_context) {
- Profile* profile = static_cast<Profile*>(browser_context);
- ChromeURLDataManager* manager = profile->GetChromeURLDataManager();
- for (size_t i = 0; i < arraysize(kAboutSourceNames); i++) {
- if (name == kAboutSourceNames[i]) {
- manager->AddDataSource(new AboutSource(name, profile));
- return;
- }
- }
+AboutUI::AboutUI(TabContents* contents, const std::string& name)
+ : ChromeWebUI(contents) {
+ Profile* profile = Profile::FromBrowserContext(contents->browser_context());
+ ChromeURLDataManager::DataSource* source =
+ new AboutUIHTMLSource(name, profile);
+ if (source)
+ profile->GetChromeURLDataManager()->AddDataSource(source);
}
-
-bool WillHandleBrowserAboutURL(GURL* url,
- content::BrowserContext* browser_context) {
- // TODO(msw): Eliminate "about:*" constants and literals from code and tests,
- // then hopefully we can remove this forced fixup.
- *url = URLFixerUpper::FixupURL(url->possibly_invalid_spec(), std::string());
-
- // Check that about: URLs are fixed up to chrome: by URLFixerUpper::FixupURL.
- DCHECK((*url == GURL(chrome::kAboutBlankURL)) ||
- !url->SchemeIs(chrome::kAboutScheme));
-
- // Only handle chrome://foo/, URLFixerUpper::FixupURL translates about:foo.
- // TAB_CONTENTS_WEB handles about:blank, which frames are allowed to access.
- if (!url->SchemeIs(chrome::kChromeUIScheme))
- return false;
-
- // Circumvent processing URLs that the renderer process will handle.
- if (chrome_about_handler::WillHandle(*url))
- return false;
-
- std::string host(url->host());
- std::string path;
- // Replace about with chrome-urls.
- if (host == chrome::kChromeUIAboutHost)
- host = chrome::kChromeUIChromeURLsHost;
- // Replace cache with view-http-cache.
- if (host == chrome::kChromeUICacheHost) {
- host = chrome::kChromeUINetworkViewCacheHost;
- // Replace gpu with gpu-internals.
- } else if (host == chrome::kChromeUIGpuHost) {
- host = chrome::kChromeUIGpuInternalsHost;
- // Replace sync with sync-internals (for legacy reasons).
- } else if (host == chrome::kChromeUISyncHost) {
- host = chrome::kChromeUISyncInternalsHost;
- // Redirect chrome://extensions to chrome://settings/extensions.
- } else if (host == chrome::kChromeUIExtensionsHost) {
- host = chrome::kChromeUISettingsHost;
- path = chrome::kExtensionsSubPage;
- }
- GURL::Replacements replacements;
- replacements.SetHostStr(host);
- if (!path.empty())
- replacements.SetPathStr(path);
- *url = url->ReplaceComponents(replacements);
-
- // Handle URLs to crash the browser or wreck the gpu process.
- if (host == chrome::kChromeUIBrowserCrashHost) {
- // Induce an intentional crash in the browser process.
- CHECK(false);
- } else if (host == chrome::kChromeUIGpuCleanHost) {
- GpuProcessHostUIShim* shim = GpuProcessHostUIShim::FromID(0);
- if (shim)
- shim->SimulateRemoveAllContext();
- } else if (host == chrome::kChromeUIGpuCrashHost) {
- GpuProcessHostUIShim* shim = GpuProcessHostUIShim::FromID(0);
- if (shim)
- shim->SimulateCrash();
- } else if (host == chrome::kChromeUIGpuHangHost) {
- GpuProcessHostUIShim* shim = GpuProcessHostUIShim::FromID(0);
- if (shim)
- shim->SimulateHang();
-#if defined(OS_CHROMEOS)
- } else if (host == chrome::kChromeUIRotateHost) {
- sensors::ScreenOrientation change;
- std::string query(url->query());
- if (query == "left") {
- change.upward = sensors::ScreenOrientation::LEFT;
- } else if (query == "right") {
- change.upward = sensors::ScreenOrientation::RIGHT;
- } else if (query == "top") {
- change.upward = sensors::ScreenOrientation::TOP;
- } else if (query == "bottom") {
- change.upward = sensors::ScreenOrientation::BOTTOM;
- } else {
- NOTREACHED() << "Unknown orientation";
- }
- sensors::Provider::GetInstance()->ScreenOrientationChanged(change);
- // Nothing to communicate to the user, so show a blank page.
- host = chrome::kChromeUIBlankHost;
- *url = GURL(chrome::kChromeUIBlankHost);
-#endif
- }
-
- // Initialize any potentially corresponding AboutSource handler.
- InitializeAboutDataSource(host, browser_context);
- return true;
-}
-
-bool HandleNonNavigationAboutURL(const GURL& url) {
- // chrome://ipc/ is currently buggy, so we disable it for official builds.
-#if !defined(OFFICIAL_BUILD)
-
-#if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(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.
- browser::ShowAboutIPCDialog();
- return true;
- }
-#endif
-
-#endif // OFFICIAL_BUILD
-
- return false;
-}
-
-std::vector<std::string> ChromePaths() {
- std::vector<std::string> paths;
- paths.reserve(arraysize(kChromePaths));
- for (size_t i = 0; i < arraysize(kChromePaths); i++)
- paths.push_back(kChromePaths[i]);
- return paths;
-}
« no previous file with comments | « chrome/browser/ui/webui/about_ui.h ('k') | chrome/browser/ui/webui/chrome_web_ui_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698