| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/browser_about_handler.h" | 5 #include "chrome/browser/browser_about_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 kVersionPath, | 153 kVersionPath, |
| 154 #if defined(OS_LINUX) | 154 #if defined(OS_LINUX) |
| 155 kSandboxPath, | 155 kSandboxPath, |
| 156 #endif | 156 #endif |
| 157 #if defined(OS_CHROMEOS) | 157 #if defined(OS_CHROMEOS) |
| 158 kNetworkPath, | 158 kNetworkPath, |
| 159 kOSCreditsPath, | 159 kOSCreditsPath, |
| 160 #endif | 160 #endif |
| 161 }; | 161 }; |
| 162 | 162 |
| 163 // Points to the singleton AboutSource object, if any. |
| 164 ChromeURLDataManager::DataSource* about_source = NULL; |
| 165 |
| 163 // When you type about:memory, it actually loads an intermediate URL that | 166 // When you type about:memory, it actually loads an intermediate URL that |
| 164 // redirects you to the final page. This avoids the problem where typing | 167 // redirects you to the final page. This avoids the problem where typing |
| 165 // "about:memory" on the new tab page or any other page where a process | 168 // "about:memory" on the new tab page or any other page where a process |
| 166 // transition would occur to the about URL will cause some confusion. | 169 // transition would occur to the about URL will cause some confusion. |
| 167 // | 170 // |
| 168 // The problem is that during the processing of the memory page, there are two | 171 // The problem is that during the processing of the memory page, there are two |
| 169 // processes active, the original and the destination one. This can create the | 172 // processes active, the original and the destination one. This can create the |
| 170 // impression that we're using more resources than we actually are. This | 173 // impression that we're using more resources than we actually are. This |
| 171 // redirect solves the problem by eliminating the process transition during the | 174 // redirect solves the problem by eliminating the process transition during the |
| 172 // time that about memory is being computed. | 175 // time that about memory is being computed. |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 std::string VersionNumberToString(uint32 value) { | 685 std::string VersionNumberToString(uint32 value) { |
| 683 int hi = (value >> 8) & 0xff; | 686 int hi = (value >> 8) & 0xff; |
| 684 int low = value & 0xff; | 687 int low = value & 0xff; |
| 685 return base::IntToString(hi) + "." + base::IntToString(low); | 688 return base::IntToString(hi) + "." + base::IntToString(low); |
| 686 } | 689 } |
| 687 | 690 |
| 688 // AboutSource ----------------------------------------------------------------- | 691 // AboutSource ----------------------------------------------------------------- |
| 689 | 692 |
| 690 AboutSource::AboutSource() | 693 AboutSource::AboutSource() |
| 691 : DataSource(chrome::kAboutScheme, MessageLoop::current()) { | 694 : DataSource(chrome::kAboutScheme, MessageLoop::current()) { |
| 695 // This should be a singleton. |
| 696 DCHECK(!about_source); |
| 697 about_source = this; |
| 698 |
| 699 // Add us to the global URL handler on the IO thread. |
| 700 BrowserThread::PostTask( |
| 701 BrowserThread::IO, FROM_HERE, |
| 702 NewRunnableMethod( |
| 703 ChromeURLDataManager::GetInstance(), |
| 704 &ChromeURLDataManager::AddDataSource, |
| 705 make_scoped_refptr(this))); |
| 692 } | 706 } |
| 693 | 707 |
| 694 AboutSource::~AboutSource() { | 708 AboutSource::~AboutSource() { |
| 709 about_source = NULL; |
| 695 } | 710 } |
| 696 | 711 |
| 697 void AboutSource::StartDataRequest(const std::string& path_raw, | 712 void AboutSource::StartDataRequest(const std::string& path_raw, |
| 698 bool is_off_the_record, int request_id) { | 713 bool is_off_the_record, int request_id) { |
| 699 std::string path = path_raw; | 714 std::string path = path_raw; |
| 700 std::string info; | 715 std::string info; |
| 701 if (path.find("/") != std::string::npos) { | 716 if (path.find("/") != std::string::npos) { |
| 702 size_t pos = path.find("/"); | 717 size_t pos = path.find("/"); |
| 703 info = path.substr(pos + 1, path.length() - (pos + 1)); | 718 info = path.substr(pos + 1, path.length() - (pos + 1)); |
| 704 path = path.substr(0, pos); | 719 path = path.substr(0, pos); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 GpuProcessHostUIShim::GetInstance()->SendAboutGpuHang(); | 1047 GpuProcessHostUIShim::GetInstance()->SendAboutGpuHang(); |
| 1033 return true; | 1048 return true; |
| 1034 } | 1049 } |
| 1035 | 1050 |
| 1036 // There are a few about: URLs that we hand over to the renderer. If the | 1051 // There are a few about: URLs that we hand over to the renderer. If the |
| 1037 // renderer wants them, don't do any rewriting. | 1052 // renderer wants them, don't do any rewriting. |
| 1038 if (chrome_about_handler::WillHandle(*url)) | 1053 if (chrome_about_handler::WillHandle(*url)) |
| 1039 return false; | 1054 return false; |
| 1040 | 1055 |
| 1041 // Anything else requires our special handler; make sure it's initialized. | 1056 // Anything else requires our special handler; make sure it's initialized. |
| 1042 InitializeAboutDataSource(profile); | 1057 InitializeAboutDataSource(); |
| 1043 | 1058 |
| 1044 // Special case about:memory to go through a redirect before ending up on | 1059 // Special case about:memory to go through a redirect before ending up on |
| 1045 // the final page. See GetAboutMemoryRedirectResponse above for why. | 1060 // the final page. See GetAboutMemoryRedirectResponse above for why. |
| 1046 if (LowerCaseEqualsASCII(url->path(), kMemoryPath)) { | 1061 if (LowerCaseEqualsASCII(url->path(), kMemoryPath)) { |
| 1047 *url = GURL("chrome://about/memory-redirect"); | 1062 *url = GURL("chrome://about/memory-redirect"); |
| 1048 return true; | 1063 return true; |
| 1049 } | 1064 } |
| 1050 | 1065 |
| 1051 // Rewrite the about URL to use chrome:. WebKit treats all about URLS the | 1066 // Rewrite the about URL to use chrome:. WebKit treats all about URLS the |
| 1052 // same (blank page), so if we want to display content, we need another | 1067 // same (blank page), so if we want to display content, we need another |
| 1053 // scheme. | 1068 // scheme. |
| 1054 std::string about_url = "chrome://about/"; | 1069 std::string about_url = "chrome://about/"; |
| 1055 about_url.append(url->path()); | 1070 about_url.append(url->path()); |
| 1056 *url = GURL(about_url); | 1071 *url = GURL(about_url); |
| 1057 return true; | 1072 return true; |
| 1058 } | 1073 } |
| 1059 | 1074 |
| 1060 void InitializeAboutDataSource(Profile* profile) { | 1075 void InitializeAboutDataSource() { |
| 1061 profile->GetChromeURLDataManager()->AddDataSource(new AboutSource()); | 1076 // We only need to register the AboutSource once and it is kept globally. |
| 1077 // There is currently no way to remove a data source. |
| 1078 static bool initialized = false; |
| 1079 if (!initialized) { |
| 1080 about_source = new AboutSource(); |
| 1081 initialized = true; |
| 1082 } |
| 1062 } | 1083 } |
| 1063 | 1084 |
| 1064 // This function gets called with the fixed-up chrome: URLs, so we have to | 1085 // This function gets called with the fixed-up chrome: URLs, so we have to |
| 1065 // compare against those instead of "about:blah". | 1086 // compare against those instead of "about:blah". |
| 1066 bool HandleNonNavigationAboutURL(const GURL& url) { | 1087 bool HandleNonNavigationAboutURL(const GURL& url) { |
| 1067 // about:ipc is currently buggy, so we disable it for official builds. | 1088 // about:ipc is currently buggy, so we disable it for official builds. |
| 1068 #if !defined(OFFICIAL_BUILD) | 1089 #if !defined(OFFICIAL_BUILD) |
| 1069 | 1090 |
| 1070 #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED) | 1091 #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED) |
| 1071 if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) { | 1092 if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) { |
| 1072 // Run the dialog. This will re-use the existing one if it's already up. | 1093 // Run the dialog. This will re-use the existing one if it's already up. |
| 1073 browser::ShowAboutIPCDialog(); | 1094 browser::ShowAboutIPCDialog(); |
| 1074 return true; | 1095 return true; |
| 1075 } | 1096 } |
| 1076 #endif | 1097 #endif |
| 1077 | 1098 |
| 1078 #endif // OFFICIAL_BUILD | 1099 #endif // OFFICIAL_BUILD |
| 1079 | 1100 |
| 1080 return false; | 1101 return false; |
| 1081 } | 1102 } |
| OLD | NEW |