[M120][Tizen][Onscreen] Fix build errors for TV profile
[platform/framework/web/chromium-efl.git] / chrome / browser / browser_about_handler.cc
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.
4
5 #include "chrome/browser/browser_about_handler.h"
6
7 #include <string>
8
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"
21
22 bool HandleChromeAboutAndChromeSyncRewrite(
23     GURL* url,
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)
28   // or
29   // 2) blocked (by content::RenderProcessHostImpl::FilterURL applied to
30   //    renderer-initiated navigations)
31   DCHECK(url->IsAboutBlank() || url->IsAboutSrcdoc() ||
32          !url->SchemeIs(url::kAboutScheme));
33
34   // Only handle chrome: URLs.
35   if (!url->SchemeIs(content::kChromeUIScheme))
36     return false;
37
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;
45   }
46
47   if (host != url->host()) {
48     GURL::Replacements replacements;
49     replacements.SetHostStr(host);
50     *url = url->ReplaceComponents(replacements);
51   }
52
53   // Having re-written the URL, make the chrome: handler process it.
54   return false;
55 }
56
57 bool HandleNonNavigationAboutURL(const GURL& url) {
58   if (!url.is_valid()) {
59     return false;
60   }
61   const std::string spec(url.spec());
62
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));
68     return true;
69   }
70   if (base::EqualsCaseInsensitiveASCII(spec, chrome::kChromeUIQuitURL)) {
71     base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
72         FROM_HERE, base::BindOnce(&chrome::AttemptExit));
73     return true;
74   }
75
76   return false;
77 }