| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   186 // time that about memory is being computed. |   186 // time that about memory is being computed. | 
|   187 std::string GetAboutMemoryRedirectResponse() { |   187 std::string GetAboutMemoryRedirectResponse() { | 
|   188   return "<meta http-equiv=\"refresh\" " |   188   return "<meta http-equiv=\"refresh\" " | 
|   189       "content=\"0;chrome://about/memory\">"; |   189       "content=\"0;chrome://about/memory\">"; | 
|   190 } |   190 } | 
|   191  |   191  | 
|   192 class AboutSource : public ChromeURLDataManager::DataSource { |   192 class AboutSource : public ChromeURLDataManager::DataSource { | 
|   193  public: |   193  public: | 
|   194   // Creates our datasource. |   194   // Creates our datasource. | 
|   195   AboutSource(); |   195   AboutSource(); | 
 |   196   explicit AboutSource(Profile* profile); | 
|   196  |   197  | 
|   197   // Called when the network layer has requested a resource underneath |   198   // Called when the network layer has requested a resource underneath | 
|   198   // the path we registered. |   199   // the path we registered. | 
|   199   virtual void StartDataRequest(const std::string& path, |   200   virtual void StartDataRequest(const std::string& path, | 
|   200                                 bool is_incognito, |   201                                 bool is_incognito, | 
|   201                                 int request_id); |   202                                 int request_id); | 
|   202  |   203  | 
|   203   virtual std::string GetMimeType(const std::string&) const { |   204   virtual std::string GetMimeType(const std::string&) const { | 
|   204     return "text/html"; |   205     return "text/html"; | 
|   205   } |   206   } | 
|   206  |   207  | 
|   207   // Send the response data. |   208   // Send the response data. | 
|   208   void FinishDataRequest(const std::string& html, int request_id); |   209   void FinishDataRequest(const std::string& html, int request_id); | 
|   209  |   210  | 
 |   211   Profile* profile() { return profile_; } | 
 |   212  | 
|   210  private: |   213  private: | 
|   211   virtual ~AboutSource(); |   214   virtual ~AboutSource(); | 
|   212  |   215  | 
 |   216   Profile* profile_; | 
 |   217  | 
|   213   DISALLOW_COPY_AND_ASSIGN(AboutSource); |   218   DISALLOW_COPY_AND_ASSIGN(AboutSource); | 
|   214 }; |   219 }; | 
|   215  |   220  | 
|   216 // Handling about:memory is complicated enough to encapsulate its related |   221 // Handling about:memory is complicated enough to encapsulate its related | 
|   217 // methods into a single class. The user should create it (on the heap) and call |   222 // methods into a single class. The user should create it (on the heap) and call | 
|   218 // its |StartFetch()| method. |   223 // its |StartFetch()| method. | 
|   219 class AboutMemoryHandler : public MemoryDetails { |   224 class AboutMemoryHandler : public MemoryDetails { | 
|   220  public: |   225  public: | 
|   221   AboutMemoryHandler(AboutSource* source, int request_id) |   226   AboutMemoryHandler(AboutSource* source, int request_id) | 
|   222     : source_(source), request_id_(request_id) {} |   227     : source_(source), request_id_(request_id) {} | 
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   897     data.append("<p style=\"color: red\">"); |   902     data.append("<p style=\"color: red\">"); | 
|   898     data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_BAD)); |   903     data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_BAD)); | 
|   899   } |   904   } | 
|   900   data.append("</p>"); |   905   data.append("</p>"); | 
|   901  |   906  | 
|   902   data.append("</body></html>\n"); |   907   data.append("</body></html>\n"); | 
|   903   return data; |   908   return data; | 
|   904 } |   909 } | 
|   905 #endif |   910 #endif | 
|   906  |   911  | 
|   907 std::string AboutVersion(DictionaryValue* localized_strings) { |   912 std::string AboutVersion(DictionaryValue* localized_strings, Profile* profile) { | 
|   908   localized_strings->SetString("title", |   913   localized_strings->SetString("title", | 
|   909       l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_TITLE)); |   914       l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_TITLE)); | 
|   910   chrome::VersionInfo version_info; |   915   chrome::VersionInfo version_info; | 
|   911  |   916  | 
|   912   std::string webkit_version = webkit_glue::GetWebKitVersion(); |   917   std::string webkit_version = webkit_glue::GetWebKitVersion(); | 
|   913 #ifdef CHROME_V8 |   918 #ifdef CHROME_V8 | 
|   914   std::string js_version(v8::V8::GetVersion()); |   919   std::string js_version(v8::V8::GetVersion()); | 
|   915   std::string js_engine = "V8"; |   920   std::string js_engine = "V8"; | 
|   916 #else |   921 #else | 
|   917   std::string js_version = webkit_version; |   922   std::string js_version = webkit_version; | 
|   918   std::string js_engine = "JavaScriptCore"; |   923   std::string js_engine = "JavaScriptCore"; | 
|   919 #endif |   924 #endif | 
|   920  |   925  | 
|   921   localized_strings->SetString("name", |   926   localized_strings->SetString("name", | 
|   922       l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |   927       l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 
|   923   localized_strings->SetString("version", version_info.Version()); |   928   localized_strings->SetString("version", version_info.Version()); | 
|   924   // Bug 79458: Need to evaluate the use of getting the version string on |   929   // Bug 79458: Need to evaluate the use of getting the version string on | 
|   925   // this thread. |   930   // this thread. | 
|   926   base::ThreadRestrictions::ScopedAllowIO allow_io; |   931   base::ThreadRestrictions::ScopedAllowIO allow_io; | 
|   927   localized_strings->SetString("version_modifier", |   932   localized_strings->SetString("version_modifier", | 
|   928                                platform_util::GetVersionStringModifier()); |   933                                platform_util::GetVersionStringModifier()); | 
 |   934   localized_strings->SetString("os_name", | 
 |   935                                l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_OS)); | 
 |   936   localized_strings->SetString("os_type", version_info.OSType()); | 
 |   937   localized_strings->SetString("webkit_version", webkit_version); | 
|   929   localized_strings->SetString("js_engine", js_engine); |   938   localized_strings->SetString("js_engine", js_engine); | 
|   930   localized_strings->SetString("js_version", js_version); |   939   localized_strings->SetString("js_version", js_version); | 
|   931  |   940  | 
|   932   // Obtain the version of the first enabled Flash plugin. |   941   // Obtain the version of the first enabled Flash plugin. | 
|   933   std::vector<webkit::npapi::WebPluginInfo> info_array; |   942   std::vector<webkit::npapi::WebPluginInfo> info_array; | 
|   934   webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( |   943   webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( | 
|   935       GURL(), "application/x-shockwave-flash", false, &info_array, NULL); |   944       GURL(), "application/x-shockwave-flash", false, &info_array, NULL); | 
|   936   string16 flash_version = |   945   string16 flash_version = | 
|   937       l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN); |   946       l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN); | 
|   938   for (size_t i = 0; i < info_array.size(); ++i) { |   947   for (size_t i = 0; i < info_array.size(); ++i) { | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
|   967   std::string command_line = ""; |   976   std::string command_line = ""; | 
|   968   typedef std::vector<std::string> ArgvList; |   977   typedef std::vector<std::string> ArgvList; | 
|   969   const ArgvList& argv = CommandLine::ForCurrentProcess()->argv(); |   978   const ArgvList& argv = CommandLine::ForCurrentProcess()->argv(); | 
|   970   for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++) |   979   for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++) | 
|   971     command_line += " " + *iter; |   980     command_line += " " + *iter; | 
|   972   // TODO(viettrungluu): |command_line| could really have any encoding, whereas |   981   // TODO(viettrungluu): |command_line| could really have any encoding, whereas | 
|   973   // below we assumes it's UTF-8. |   982   // below we assumes it's UTF-8. | 
|   974   localized_strings->SetString("command_line", command_line); |   983   localized_strings->SetString("command_line", command_line); | 
|   975 #endif |   984 #endif | 
|   976  |   985  | 
 |   986   // Allow IO temporarily based on allow_io (defined above) | 
 |   987   // since the following operation will complete quickly | 
 |   988   localized_strings->SetString("executable_path_name", | 
 |   989       l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_EXECUTABLE_PATH)); | 
 |   990   FilePath executable_path = CommandLine::ForCurrentProcess()->GetProgram(); | 
 |   991   if (file_util::AbsolutePath(&executable_path)) { | 
 |   992     localized_strings->SetString("executable_path", executable_path.value()); | 
 |   993   } else { | 
 |   994     localized_strings->SetString("executable_path", | 
 |   995         l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND)); | 
 |   996   } | 
 |   997   localized_strings->SetString("profile_path_name", | 
 |   998       l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PROFILE_PATH)); | 
 |   999   if (profile) { | 
 |  1000     FilePath profile_path = profile->GetPath(); | 
 |  1001     if (file_util::AbsolutePath(&profile_path)) { | 
 |  1002       localized_strings->SetString("profile_path", profile_path.value()); | 
 |  1003     } else { | 
 |  1004       localized_strings->SetString("profile_path", | 
 |  1005           l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND)); | 
 |  1006     } | 
 |  1007   } else { | 
 |  1008     localized_strings->SetString("profile_path", | 
 |  1009         l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND)); | 
 |  1010   } | 
 |  1011  | 
|   977   base::StringPiece version_html( |  1012   base::StringPiece version_html( | 
|   978       ResourceBundle::GetSharedInstance().GetRawDataResource( |  1013       ResourceBundle::GetSharedInstance().GetRawDataResource( | 
|   979           IDR_ABOUT_VERSION_HTML)); |  1014           IDR_ABOUT_VERSION_HTML)); | 
|   980  |  1015  | 
|   981   return jstemplate_builder::GetTemplatesHtml( |  1016   return jstemplate_builder::GetTemplatesHtml( | 
|   982       version_html, localized_strings, "t" /* template root node id */); |  1017       version_html, localized_strings, "t" /* template root node id */); | 
|   983 } |  1018 } | 
|   984  |  1019  | 
|   985 // AboutSource ----------------------------------------------------------------- |  1020 // AboutSource ----------------------------------------------------------------- | 
|   986  |  1021  | 
|   987 AboutSource::AboutSource() |  1022 AboutSource::AboutSource() | 
|   988     : DataSource(chrome::kAboutScheme, MessageLoop::current()) { |  1023     : DataSource(chrome::kAboutScheme, MessageLoop::current()) { | 
|   989 } |  1024 } | 
|   990  |  1025  | 
 |  1026 AboutSource::AboutSource(Profile* profile) | 
 |  1027     : DataSource(chrome::kAboutScheme, MessageLoop::current()), | 
 |  1028       profile_(profile) { | 
 |  1029 } | 
 |  1030  | 
|   991 AboutSource::~AboutSource() { |  1031 AboutSource::~AboutSource() { | 
|   992 } |  1032 } | 
|   993  |  1033  | 
|   994 void AboutSource::StartDataRequest(const std::string& path_raw, |  1034 void AboutSource::StartDataRequest(const std::string& path_raw, | 
|   995     bool is_incognito, int request_id) { |  1035     bool is_incognito, int request_id) { | 
|   996   std::string path = path_raw; |  1036   std::string path = path_raw; | 
|   997   std::string info; |  1037   std::string info; | 
|   998   if (path.find("/") != std::string::npos) { |  1038   if (path.find("/") != std::string::npos) { | 
|   999     size_t pos = path.find("/"); |  1039     size_t pos = path.find("/"); | 
|  1000     info = path.substr(pos + 1, path.length() - (pos + 1)); |  1040     info = path.substr(pos + 1, path.length() - (pos + 1)); | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
|  1021     response = AboutStats(info); |  1061     response = AboutStats(info); | 
|  1022 #if defined(USE_TCMALLOC) |  1062 #if defined(USE_TCMALLOC) | 
|  1023   } else if (path == kTcmallocPath) { |  1063   } else if (path == kTcmallocPath) { | 
|  1024     response = AboutTcmalloc(info); |  1064     response = AboutTcmalloc(info); | 
|  1025 #endif |  1065 #endif | 
|  1026   } else if (path == kVersionPath || path.empty()) { |  1066   } else if (path == kVersionPath || path.empty()) { | 
|  1027 #if defined(OS_CHROMEOS) |  1067 #if defined(OS_CHROMEOS) | 
|  1028     new ChromeOSAboutVersionHandler(this, request_id); |  1068     new ChromeOSAboutVersionHandler(this, request_id); | 
|  1029     return; |  1069     return; | 
|  1030 #else |  1070 #else | 
|  1031     DictionaryValue value; |  1071     DictionaryValue localized_strings; | 
|  1032     response = AboutVersion(&value); |  1072     localized_strings.SetString("os_version", ""); | 
 |  1073     response = AboutVersion(&localized_strings, profile_); | 
|  1033 #endif |  1074 #endif | 
|  1034   } else if (path == kCreditsPath) { |  1075   } else if (path == kCreditsPath) { | 
|  1035     response = ResourceBundle::GetSharedInstance().GetRawDataResource( |  1076     response = ResourceBundle::GetSharedInstance().GetRawDataResource( | 
|  1036         IDR_CREDITS_HTML).as_string(); |  1077         IDR_CREDITS_HTML).as_string(); | 
|  1037   } else if (path == kAboutPath) { |  1078   } else if (path == kAboutPath) { | 
|  1038     response = AboutAbout(); |  1079     response = AboutAbout(); | 
|  1039 #if defined(OS_CHROMEOS) |  1080 #if defined(OS_CHROMEOS) | 
|  1040   } else if (path == kOSCreditsPath) { |  1081   } else if (path == kOSCreditsPath) { | 
|  1041     response = ResourceBundle::GetSharedInstance().GetRawDataResource( |  1082     response = ResourceBundle::GetSharedInstance().GetRawDataResource( | 
|  1042         IDR_OS_CREDITS_HTML).as_string(); |  1083         IDR_OS_CREDITS_HTML).as_string(); | 
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1212       request_id_(request_id) { |  1253       request_id_(request_id) { | 
|  1213   loader_.GetVersion(&consumer_, |  1254   loader_.GetVersion(&consumer_, | 
|  1214                      NewCallback(this, &ChromeOSAboutVersionHandler::OnVersion), |  1255                      NewCallback(this, &ChromeOSAboutVersionHandler::OnVersion), | 
|  1215                      chromeos::VersionLoader::VERSION_FULL); |  1256                      chromeos::VersionLoader::VERSION_FULL); | 
|  1216 } |  1257 } | 
|  1217  |  1258  | 
|  1218 void ChromeOSAboutVersionHandler::OnVersion( |  1259 void ChromeOSAboutVersionHandler::OnVersion( | 
|  1219     chromeos::VersionLoader::Handle handle, |  1260     chromeos::VersionLoader::Handle handle, | 
|  1220     std::string version) { |  1261     std::string version) { | 
|  1221   DictionaryValue localized_strings; |  1262   DictionaryValue localized_strings; | 
|  1222   localized_strings.SetString("os_name", |  | 
|  1223                               l10n_util::GetStringUTF16(IDS_PRODUCT_OS_NAME)); |  | 
|  1224   localized_strings.SetString("os_version", version); |  1263   localized_strings.SetString("os_version", version); | 
|  1225   localized_strings.SetBoolean("is_chrome_os", true); |  1264   source_->FinishDataRequest(AboutVersion(&localized_strings, | 
|  1226   source_->FinishDataRequest(AboutVersion(&localized_strings), request_id_); |  1265                                           source_->profile()), request_id_); | 
|  1227  |  1266  | 
|  1228   // CancelableRequestProvider isn't happy when it's deleted and servicing a |  1267   // CancelableRequestProvider isn't happy when it's deleted and servicing a | 
|  1229   // task, so we delay the deletion. |  1268   // task, so we delay the deletion. | 
|  1230   MessageLoop::current()->DeleteSoon(FROM_HERE, this); |  1269   MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 
|  1231 } |  1270 } | 
|  1232  |  1271  | 
|  1233 #endif |  1272 #endif | 
|  1234  |  1273  | 
|  1235 // Returns true if |url|'s spec starts with |about_specifier|, and is |  1274 // Returns true if |url|'s spec starts with |about_specifier|, and is | 
|  1236 // terminated by the start of a path. |  1275 // terminated by the start of a path. | 
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1356   // Rewrite the about URL to use chrome:. WebKit treats all about URLS the |  1395   // Rewrite the about URL to use chrome:. WebKit treats all about URLS the | 
|  1357   // same (blank page), so if we want to display content, we need another |  1396   // same (blank page), so if we want to display content, we need another | 
|  1358   // scheme. |  1397   // scheme. | 
|  1359   std::string about_url = "chrome://about/"; |  1398   std::string about_url = "chrome://about/"; | 
|  1360   about_url.append(url->path()); |  1399   about_url.append(url->path()); | 
|  1361   *url = GURL(about_url); |  1400   *url = GURL(about_url); | 
|  1362   return true; |  1401   return true; | 
|  1363 } |  1402 } | 
|  1364  |  1403  | 
|  1365 void InitializeAboutDataSource(Profile* profile) { |  1404 void InitializeAboutDataSource(Profile* profile) { | 
|  1366   profile->GetChromeURLDataManager()->AddDataSource(new AboutSource()); |  1405   profile->GetChromeURLDataManager()->AddDataSource(new AboutSource(profile)); | 
|  1367 } |  1406 } | 
|  1368  |  1407  | 
|  1369 // This function gets called with the fixed-up chrome: URLs, so we have to |  1408 // This function gets called with the fixed-up chrome: URLs, so we have to | 
|  1370 // compare against those instead of "about:blah". |  1409 // compare against those instead of "about:blah". | 
|  1371 bool HandleNonNavigationAboutURL(const GURL& url) { |  1410 bool HandleNonNavigationAboutURL(const GURL& url) { | 
|  1372   // about:ipc is currently buggy, so we disable it for official builds. |  1411   // about:ipc is currently buggy, so we disable it for official builds. | 
|  1373 #if !defined(OFFICIAL_BUILD) |  1412 #if !defined(OFFICIAL_BUILD) | 
|  1374  |  1413  | 
|  1375 #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED) |  1414 #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED) | 
|  1376   if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) { |  1415   if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) { | 
|  1377     // Run the dialog. This will re-use the existing one if it's already up. |  1416     // Run the dialog. This will re-use the existing one if it's already up. | 
|  1378     browser::ShowAboutIPCDialog(); |  1417     browser::ShowAboutIPCDialog(); | 
|  1379     return true; |  1418     return true; | 
|  1380   } |  1419   } | 
|  1381 #endif |  1420 #endif | 
|  1382  |  1421  | 
|  1383 #endif  // OFFICIAL_BUILD |  1422 #endif  // OFFICIAL_BUILD | 
|  1384  |  1423  | 
|  1385   return false; |  1424   return false; | 
|  1386 } |  1425 } | 
|  1387  |  1426  | 
|  1388 std::vector<std::string> AboutPaths() { |  1427 std::vector<std::string> AboutPaths() { | 
|  1389   std::vector<std::string> paths; |  1428   std::vector<std::string> paths; | 
|  1390   paths.reserve(arraysize(kAllAboutPaths)); |  1429   paths.reserve(arraysize(kAllAboutPaths)); | 
|  1391   for (size_t i = 0; i < arraysize(kAllAboutPaths); i++) |  1430   for (size_t i = 0; i < arraysize(kAllAboutPaths); i++) | 
|  1392     paths.push_back(kAllAboutPaths[i]); |  1431     paths.push_back(kAllAboutPaths[i]); | 
|  1393   return paths; |  1432   return paths; | 
|  1394 } |  1433 } | 
| OLD | NEW |