blob: af2282034336ab80a311f0314dbc2d6eb43ad045 [file] [log] [blame]
[email protected]1640a852012-01-05 21:05:381// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/browser_about_handler.h"
6
7#include <string>
initial.commit09911bf2008-07-26 23:55:298
andresantoso063151d2014-12-18 22:37:559#include "base/bind.h"
Hans Wennborg1790e6b2020-04-24 19:10:3310#include "base/check.h"
skyostil02598352015-06-12 12:37:2511#include "base/location.h"
skyostil02598352015-06-12 12:37:2512#include "base/single_thread_task_runner.h"
[email protected]e7463412013-06-10 22:53:4613#include "base/strings/string_util.h"
gabb15e19072016-05-11 20:45:4114#include "base/threading/thread_task_runner_handle.h"
[email protected]c5955d92013-07-02 00:14:1615#include "chrome/browser/lifetime/application_lifetime.h"
calamity20fc2af2016-06-09 02:02:5816#include "chrome/browser/profiles/profile.h"
[email protected]c96531e82011-01-26 03:11:1417#include "chrome/browser/ui/browser_dialogs.h"
ddoman61ec1422016-03-17 05:03:4218#include "chrome/common/chrome_features.h"
[email protected]727903e12014-08-14 16:51:2619#include "chrome/common/chrome_switches.h"
[email protected]dcf7d352009-02-26 01:56:0220#include "chrome/common/url_constants.h"
rsleevi24f64dc22015-08-07 21:39:2121#include "components/url_formatter/url_fixer.h"
twellingtona0d282e2017-02-07 16:36:3922#include "content/public/common/content_features.h"
Scott Violetc8240b02018-03-08 22:03:5923#include "extensions/buildflags/buildflags.h"
[email protected]18bc42c92009-02-04 18:59:0924
creis94a977f62015-02-18 23:51:0525bool FixupBrowserAboutURL(GURL* url,
26 content::BrowserContext* browser_context) {
27 // Ensure that any cleanup done by FixupURL happens before the rewriting
28 // phase that determines the virtual URL, by including it in an initial
29 // URLHandler. This prevents minor changes from producing a virtual URL,
30 // which could lead to a URL spoof.
rsleevi24f64dc22015-08-07 21:39:2131 *url = url_formatter::FixupURL(url->possibly_invalid_spec(), std::string());
creis94a977f62015-02-18 23:51:0532 return true;
33}
34
[email protected]3d7474ff2011-07-27 17:47:3735bool WillHandleBrowserAboutURL(GURL* url,
36 content::BrowserContext* browser_context) {
[email protected]89f550b2011-06-08 18:34:0337 // TODO(msw): Eliminate "about:*" constants and literals from code and tests,
38 // then hopefully we can remove this forced fixup.
creis94a977f62015-02-18 23:51:0539 FixupBrowserAboutURL(url, browser_context);
[email protected]89f550b2011-06-08 18:34:0340
rsleevi24f64dc22015-08-07 21:39:2141 // Check that about: URLs are fixed up to chrome: by url_formatter::FixupURL.
Lukasz Anforowicz0bc073e2019-06-14 19:41:5242 DCHECK(url->IsAboutBlank() || url->IsAboutSrcdoc() ||
43 !url->SchemeIs(url::kAboutScheme));
[email protected]89f550b2011-06-08 18:34:0344
rsleevi24f64dc22015-08-07 21:39:2145 // Only handle chrome://foo/, url_formatter::FixupURL translates about:foo.
[email protected]2d9748b22014-02-11 00:17:2946 if (!url->SchemeIs(content::kChromeUIScheme))
[email protected]cd3d7892009-03-04 23:55:0647 return false;
48
[email protected]89f550b2011-06-08 18:34:0349 std::string host(url->host());
[email protected]dd86ba302011-09-19 20:10:3750 std::string path;
dbeam25b548f2017-05-05 18:05:2451
sauskib5f82762020-07-21 17:13:2252 // Do not handle chrome://settings rewrites, they are handled in the
53 // HandleWebUI handler.
thestig76cc70a2017-06-07 05:29:4354 if (host == chrome::kChromeUISettingsHost)
sauskib5f82762020-07-21 17:13:2255 return false;
thestig76cc70a2017-06-07 05:29:4356
57 // Do not handle chrome://help.
58 if (host == chrome::kChromeUIHelpHost)
59 return false; // Handled in the HandleWebUI handler.
60
[email protected]89f550b2011-06-08 18:34:0361 // Replace about with chrome-urls.
62 if (host == chrome::kChromeUIAboutHost)
63 host = chrome::kChromeUIChromeURLsHost;
dbeam25b548f2017-05-05 18:05:2464
Eric Roman6ebc11f2018-02-21 19:32:2465 if (host == chrome::kChromeUISyncHost) {
66 // Replace sync with sync-internals (for legacy reasons).
[email protected]89f550b2011-06-08 18:34:0367 host = chrome::kChromeUISyncInternalsHost;
thestigc839b552017-03-23 02:38:5668 } else if (host == chrome::kChromeUIHistoryHost) {
dbeame1a5fa52017-06-07 02:27:3769 // Redirect chrome://history.
dbeam25b548f2017-05-05 18:05:2470 path = url->path();
[email protected]dd86ba302011-09-19 20:10:3771 }
[email protected]eb04af82013-09-04 00:49:2972
[email protected]89f550b2011-06-08 18:34:0373 GURL::Replacements replacements;
74 replacements.SetHostStr(host);
[email protected]dd86ba302011-09-19 20:10:3775 if (!path.empty())
76 replacements.SetPathStr(path);
[email protected]89f550b2011-06-08 18:34:0377 *url = url->ReplaceComponents(replacements);
[email protected]cd3d7892009-03-04 23:55:0678
[email protected]b3adbd02011-11-30 22:23:2779 // Having re-written the URL, make the chrome: handler process it.
80 return false;
[email protected]cd3d7892009-03-04 23:55:0681}
82
[email protected]cd3d7892009-03-04 23:55:0683bool HandleNonNavigationAboutURL(const GURL& url) {
avi861ff752014-09-23 22:55:3384 const std::string spec(url.spec());
[email protected]594458a2013-12-05 12:40:2485
brettwbc17d2c82015-06-09 22:39:0886 if (base::LowerCaseEqualsASCII(spec, chrome::kChromeUIRestartURL)) {
[email protected]594458a2013-12-05 12:40:2487 // Call AttemptRestart after chrome::Navigate() completes to avoid access of
88 // gtk objects after they are destroyed by BrowserWindowGtk::Close().
skyostil02598352015-06-12 12:37:2589 base::ThreadTaskRunnerHandle::Get()->PostTask(
tzik29ea5c72017-04-20 02:16:5190 FROM_HERE, base::BindOnce(&chrome::AttemptRestart));
[email protected]594458a2013-12-05 12:40:2491 return true;
thestig76cc70a2017-06-07 05:29:4392 }
93 if (base::LowerCaseEqualsASCII(spec, chrome::kChromeUIQuitURL)) {
skyostil02598352015-06-12 12:37:2594 base::ThreadTaskRunnerHandle::Get()->PostTask(
tzik29ea5c72017-04-20 02:16:5195 FROM_HERE, base::BindOnce(&chrome::AttemptExit));
[email protected]594458a2013-12-05 12:40:2496 return true;
97 }
98
[email protected]cd3d7892009-03-04 23:55:0699 return false;
initial.commit09911bf2008-07-26 23:55:29100}