| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 7 #include <string> | 
| 8 | 8 | 
| 9 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "base/location.h" | 10 #include "base/location.h" | 
| 11 #include "base/logging.h" | 11 #include "base/logging.h" | 
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" | 
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" | 
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" | 
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" | 
| 16 #include "chrome/browser/lifetime/application_lifetime.h" | 16 #include "chrome/browser/lifetime/application_lifetime.h" | 
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" | 
| 18 #include "chrome/browser/ui/browser_dialogs.h" | 18 #include "chrome/browser/ui/browser_dialogs.h" | 
| 19 #include "chrome/common/chrome_features.h" | 19 #include "chrome/common/chrome_features.h" | 
| 20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" | 
| 21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" | 
| 22 #include "components/url_formatter/url_fixer.h" | 22 #include "components/url_formatter/url_fixer.h" | 
| 23 #include "content/public/common/content_features.h" | 23 #include "content/public/common/content_features.h" | 
| 24 #include "extensions/features/features.h" | 24 #include "extensions/features/features.h" | 
| 25 | 25 | 
| 26 #if !defined(OS_ANDROID) |  | 
| 27 #include "chrome/browser/ui/webui/md_history_ui.h" |  | 
| 28 #endif |  | 
| 29 |  | 
| 30 #if defined(OS_ANDROID) | 26 #if defined(OS_ANDROID) | 
| 31 #include "chrome/browser/android/chrome_feature_list.h" | 27 #include "chrome/browser/android/chrome_feature_list.h" | 
| 32 #endif | 28 #endif | 
| 33 | 29 | 
| 34 bool FixupBrowserAboutURL(GURL* url, | 30 bool FixupBrowserAboutURL(GURL* url, | 
| 35                           content::BrowserContext* browser_context) { | 31                           content::BrowserContext* browser_context) { | 
| 36   // Ensure that any cleanup done by FixupURL happens before the rewriting | 32   // Ensure that any cleanup done by FixupURL happens before the rewriting | 
| 37   // phase that determines the virtual URL, by including it in an initial | 33   // phase that determines the virtual URL, by including it in an initial | 
| 38   // URLHandler.  This prevents minor changes from producing a virtual URL, | 34   // URLHandler.  This prevents minor changes from producing a virtual URL, | 
| 39   // which could lead to a URL spoof. | 35   // which could lead to a URL spoof. | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 50   // Check that about: URLs are fixed up to chrome: by url_formatter::FixupURL. | 46   // Check that about: URLs are fixed up to chrome: by url_formatter::FixupURL. | 
| 51   DCHECK((*url == url::kAboutBlankURL) || | 47   DCHECK((*url == url::kAboutBlankURL) || | 
| 52          !url->SchemeIs(url::kAboutScheme)); | 48          !url->SchemeIs(url::kAboutScheme)); | 
| 53 | 49 | 
| 54   // Only handle chrome://foo/, url_formatter::FixupURL translates about:foo. | 50   // Only handle chrome://foo/, url_formatter::FixupURL translates about:foo. | 
| 55   if (!url->SchemeIs(content::kChromeUIScheme)) | 51   if (!url->SchemeIs(content::kChromeUIScheme)) | 
| 56     return false; | 52     return false; | 
| 57 | 53 | 
| 58   std::string host(url->host()); | 54   std::string host(url->host()); | 
| 59   std::string path; | 55   std::string path; | 
|  | 56 | 
| 60   // Replace about with chrome-urls. | 57   // Replace about with chrome-urls. | 
| 61   if (host == chrome::kChromeUIAboutHost) | 58   if (host == chrome::kChromeUIAboutHost) | 
| 62     host = chrome::kChromeUIChromeURLsHost; | 59     host = chrome::kChromeUIChromeURLsHost; | 
|  | 60 | 
|  | 61   // Legacy redirect from chrome://history-frame to chrome://history. | 
|  | 62   if (host == chrome::kDeprecatedChromeUIHistoryFrameHost) | 
|  | 63     host = chrome::kChromeUIHistoryHost; | 
|  | 64 | 
| 63   // Replace cache with view-http-cache. | 65   // Replace cache with view-http-cache. | 
| 64   if (host == chrome::kChromeUICacheHost) { | 66   if (host == chrome::kChromeUICacheHost) { | 
| 65     host = content::kChromeUINetworkViewCacheHost; | 67     host = content::kChromeUINetworkViewCacheHost; | 
| 66   // Replace sync with sync-internals (for legacy reasons). | 68   // Replace sync with sync-internals (for legacy reasons). | 
| 67   } else if (host == chrome::kChromeUISyncHost) { | 69   } else if (host == chrome::kChromeUISyncHost) { | 
| 68     host = chrome::kChromeUISyncInternalsHost; | 70     host = chrome::kChromeUISyncInternalsHost; | 
| 69   // Redirect chrome://extensions. | 71   // Redirect chrome://extensions. | 
| 70 #if BUILDFLAG(ENABLE_EXTENSIONS) | 72 #if BUILDFLAG(ENABLE_EXTENSIONS) | 
| 71   } else if (host == chrome::kChromeUIExtensionsHost) { | 73   } else if (host == chrome::kChromeUIExtensionsHost) { | 
| 72     // If the material design extensions page is enabled, it gets its own host. | 74     // If the material design extensions page is enabled, it gets its own host. | 
| 73     // Otherwise, it's handled by the uber settings page. | 75     // Otherwise, it's handled by the uber settings page. | 
| 74     if (base::FeatureList::IsEnabled(features::kMaterialDesignExtensions)) { | 76     if (base::FeatureList::IsEnabled(features::kMaterialDesignExtensions)) { | 
| 75       host = chrome::kChromeUIExtensionsHost; | 77       host = chrome::kChromeUIExtensionsHost; | 
| 76       path = url->path(); | 78       path = url->path(); | 
| 77     } else { | 79     } else { | 
| 78       host = chrome::kChromeUIUberHost; | 80       host = chrome::kChromeUIUberHost; | 
| 79       path = chrome::kChromeUIExtensionsHost + url->path(); | 81       path = chrome::kChromeUIExtensionsHost + url->path(); | 
| 80     } | 82     } | 
| 81   // Redirect chrome://settings/extensions (legacy URL). | 83   // Redirect chrome://settings/extensions (legacy URL). | 
| 82   } else if (host == chrome::kChromeUISettingsHost && | 84   } else if (host == chrome::kChromeUISettingsHost && | 
| 83              url->path() == | 85              url->path() == | 
| 84                  std::string("/") + chrome::kDeprecatedExtensionsSubPage) { | 86                  std::string("/") + chrome::kDeprecatedExtensionsSubPage) { | 
| 85     host = chrome::kChromeUIUberHost; | 87     host = chrome::kChromeUIUberHost; | 
| 86     path = chrome::kChromeUIExtensionsHost; | 88     path = chrome::kChromeUIExtensionsHost; | 
| 87 #endif  // BUILDFLAG(ENABLE_EXTENSIONS) | 89 #endif  // BUILDFLAG(ENABLE_EXTENSIONS) | 
| 88   // Redirect chrome://history. | 90   // Redirect chrome://history. | 
| 89   } else if (host == chrome::kChromeUIHistoryHost) { | 91   } else if (host == chrome::kChromeUIHistoryHost) { | 
| 90 #if defined(OS_ANDROID) | 92     path = url->path(); | 
| 91     // TODO(twellington): remove this after native Android history launches. |  | 
| 92     // See http://crbug.com/654071. |  | 
| 93     if (!base::FeatureList::IsEnabled(features::kNativeAndroidHistoryManager)) { |  | 
| 94       // On Android, redirect directly to chrome://history-frame since |  | 
| 95       // uber page is unsupported. |  | 
| 96       host = chrome::kChromeUIHistoryFrameHost; |  | 
| 97     } |  | 
| 98 #else |  | 
| 99     // Material design history is handled on the top-level chrome://history |  | 
| 100     // host. |  | 
| 101     if (base::FeatureList::IsEnabled(features::kMaterialDesignHistory)) { |  | 
| 102       host = chrome::kChromeUIHistoryHost; |  | 
| 103       path = url->path(); |  | 
| 104     } else { |  | 
| 105       host = chrome::kChromeUIUberHost; |  | 
| 106       path = chrome::kChromeUIHistoryHost + url->path(); |  | 
| 107     } |  | 
| 108 #endif |  | 
| 109   // Redirect chrome://settings, unless MD settings is enabled. | 93   // Redirect chrome://settings, unless MD settings is enabled. | 
| 110   } else if (host == chrome::kChromeUISettingsHost) { | 94   } else if (host == chrome::kChromeUISettingsHost) { | 
| 111     if (base::FeatureList::IsEnabled(features::kMaterialDesignSettings)) { | 95     if (base::FeatureList::IsEnabled(features::kMaterialDesignSettings)) { | 
| 112       return true;  // Prevent further rewriting - this is a valid URL. | 96       return true;  // Prevent further rewriting - this is a valid URL. | 
| 113     } else if (::switches::SettingsWindowEnabled()) { | 97     } else if (::switches::SettingsWindowEnabled()) { | 
| 114       host = chrome::kChromeUISettingsFrameHost; | 98       host = chrome::kChromeUISettingsFrameHost; | 
| 115     } else { | 99     } else { | 
| 116       host = chrome::kChromeUIUberHost; | 100       host = chrome::kChromeUIUberHost; | 
| 117       path = chrome::kChromeUISettingsHost + url->path(); | 101       path = chrome::kChromeUISettingsHost + url->path(); | 
| 118     } | 102     } | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 150         FROM_HERE, base::BindOnce(&chrome::AttemptRestart)); | 134         FROM_HERE, base::BindOnce(&chrome::AttemptRestart)); | 
| 151     return true; | 135     return true; | 
| 152   } else if (base::LowerCaseEqualsASCII(spec, chrome::kChromeUIQuitURL)) { | 136   } else if (base::LowerCaseEqualsASCII(spec, chrome::kChromeUIQuitURL)) { | 
| 153     base::ThreadTaskRunnerHandle::Get()->PostTask( | 137     base::ThreadTaskRunnerHandle::Get()->PostTask( | 
| 154         FROM_HERE, base::BindOnce(&chrome::AttemptExit)); | 138         FROM_HERE, base::BindOnce(&chrome::AttemptExit)); | 
| 155     return true; | 139     return true; | 
| 156   } | 140   } | 
| 157 | 141 | 
| 158   return false; | 142   return false; | 
| 159 } | 143 } | 
| OLD | NEW | 
|---|