1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/browser_about_handler.h"
9 #include "base/check.h"
10 #include "base/functional/bind.h"
11 #include "base/location.h"
12 #include "base/strings/string_util.h"
13 #include "base/task/single_thread_task_runner.h"
14 #include "chrome/browser/lifetime/application_lifetime.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser_dialogs.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/url_constants.h"
19 #include "content/public/common/content_features.h"
20 #include "extensions/buildflags/buildflags.h"
22 bool HandleChromeAboutAndChromeSyncRewrite(
24 content::BrowserContext* browser_context) {
25 // Check that about: URLs are either
26 // 1) fixed up to chrome: (by url_formatter::FixupURL applied to
27 // browser-initiated navigations)
29 // 2) blocked (by content::RenderProcessHostImpl::FilterURL applied to
30 // renderer-initiated navigations)
31 DCHECK(url->IsAboutBlank() || url->IsAboutSrcdoc() ||
32 !url->SchemeIs(url::kAboutScheme));
34 // Only handle chrome: URLs.
35 if (!url->SchemeIs(content::kChromeUIScheme))
38 std::string host(url->host());
39 if (host == chrome::kChromeUIAboutHost) {
40 // Replace chrome://about with chrome://chrome-urls.
41 host = chrome::kChromeUIChromeURLsHost;
42 } else if (host == chrome::kChromeUISyncHost) {
43 // Replace chrome://sync with chrome://sync-internals (for legacy reasons).
44 host = chrome::kChromeUISyncInternalsHost;
47 if (host != url->host()) {
48 GURL::Replacements replacements;
49 replacements.SetHostStr(host);
50 *url = url->ReplaceComponents(replacements);
53 // Having re-written the URL, make the chrome: handler process it.
57 bool HandleNonNavigationAboutURL(const GURL& url) {
58 if (!url.is_valid()) {
61 const std::string spec(url.spec());
63 if (base::EqualsCaseInsensitiveASCII(spec, chrome::kChromeUIRestartURL)) {
64 // Call AttemptRestart after chrome::Navigate() completes to avoid access of
65 // gtk objects after they are destroyed by BrowserWindowGtk::Close().
66 base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
67 FROM_HERE, base::BindOnce(&chrome::AttemptRestart));
70 if (base::EqualsCaseInsensitiveASCII(spec, chrome::kChromeUIQuitURL)) {
71 base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
72 FROM_HERE, base::BindOnce(&chrome::AttemptExit));