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