-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #34240: Add WebUI & Expose WebViews to iOS (#20929)
- Added WebUI implementation. - Exposed Chromium WebView Controller and WebView property to iOS. - Removed SyncInternals and Histogram controllers as the iOS side will use the WebView directly and supply its own URL.
- Loading branch information
Showing
46 changed files
with
1,783 additions
and
1,337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
include_rules = [ | ||
"+brave/components/webui/about_ui.h", | ||
"+third_party/re2", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,11 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include <string_view> | ||
|
||
#include "base/containers/contains.h" | ||
#include "base/strings/string_split.h" | ||
#include "third_party/re2/src/re2/re2.h" | ||
// Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "brave/components/webui/about_ui.h" // IWYU pragma: export | ||
#include "src/chrome/browser/ui/webui/about_ui.cc" | ||
|
||
std::string AboutUIHTMLSource::ChromeURLs() const { | ||
std::string chrome_urls = ::ChromeURLs(); | ||
|
||
// Replace Chrome -> Brave. | ||
const std::string chrome_header = "Chrome URLs"; | ||
const std::string brave_header = "Brave URLs"; | ||
const std::string chrome_pages_header = "List of Chrome URLs"; | ||
const std::string brave_pages_header = "List of Brave URLs"; | ||
const std::string chrome_internal_pages_header = | ||
"List of chrome://internals pages"; | ||
const std::string brave_internal_pages_header = | ||
"List of brave://internals pages"; | ||
const std::string chrome_url_list = ">chrome://"; | ||
const std::string brave_url_list = ">brave://"; | ||
RE2::GlobalReplace(&chrome_urls, chrome_header, brave_header); | ||
RE2::GlobalReplace(&chrome_urls, chrome_pages_header, brave_pages_header); | ||
RE2::GlobalReplace(&chrome_urls, chrome_internal_pages_header, | ||
brave_internal_pages_header); | ||
RE2::GlobalReplace(&chrome_urls, chrome_url_list, brave_url_list); | ||
|
||
// Remove some URLs. | ||
auto html_lines = base::SplitStringPiece( | ||
chrome_urls, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | ||
const base::flat_set<std::string_view> kURLsToRemove{ | ||
"brave://memories", | ||
}; | ||
// URLs in html should be sorted so it's okay to iterate over sorted | ||
// kURLsToRemove. | ||
auto html_line_it = html_lines.begin(); | ||
auto url_to_remove_it = kURLsToRemove.begin(); | ||
while (html_line_it != html_lines.end() && | ||
url_to_remove_it != kURLsToRemove.end()) { | ||
if (base::Contains(*html_line_it, *url_to_remove_it)) { | ||
html_line_it = html_lines.erase(html_line_it); | ||
++url_to_remove_it; | ||
} else { | ||
++html_line_it; | ||
} | ||
} | ||
|
||
return base::JoinString(html_lines, "\n"); | ||
return brave::ReplaceAboutUIChromeURLs(::ChromeURLs()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include_rules = [ | ||
"+brave/components/version_info/version_info.h", | ||
"+brave/components/webui/about_ui.h", | ||
"+brave/ios/browser/ui/webui/brave_web_ui_controller_factory.h", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "brave/components/webui/about_ui.h" // IWYU pragma: keep | ||
#include "ios/chrome/browser/shared/model/url/chrome_url_constants.h" // IWYU pragma: keep | ||
|
||
#define kChromeUIChromeURLsHost kChromeUIChromeURLsHost) { \ | ||
response = brave::ReplaceAboutUIChromeURLs(ChromeURLs()); \ | ||
} else if (false // NOLINT[readability/braces] | ||
|
||
#include "src/ios/chrome/browser/ui/webui/about_ui.cc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "brave/components/version_info/version_info.h" | ||
#include "components/version_info/version_info.h" | ||
|
||
#define GetVersionNumber GetBraveVersionNumberForDisplay | ||
#include "src/ios/chrome/browser/ui/webui/crashes_ui.cc" | ||
#undef GetVersionNumber |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "brave/components/version_info/version_info.h" | ||
#include "components/version_info/version_info.h" | ||
|
||
#define GetVersionNumber GetBraveVersionNumberForDisplay | ||
#include "src/ios/chrome/browser/ui/webui/version_ui.mm" | ||
#undef GetVersionNumber |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
import("//brave/build/config.gni") | ||
import("//build/buildflag_header.gni") | ||
|
||
static_library("webui") { | ||
visibility = [ | ||
"//brave/browser/ui", | ||
"//brave/ios/browser/ui/webui", | ||
] | ||
|
||
sources = [ | ||
"about_ui.cc", | ||
"about_ui.h", | ||
"webui_resources.cc", | ||
"webui_resources.h", | ||
] | ||
|
||
deps = [ | ||
"//base", | ||
"//brave/components/ai_chat/core/common/buildflags", | ||
"//brave/components/brave_rewards/resources:static_resources", | ||
"//brave/components/constants", | ||
"//brave/components/ipfs/buildflags", | ||
"//brave/components/l10n/common", | ||
"//brave/components/resources:static_resources", | ||
"//brave/components/resources:strings_grit", | ||
"//brave/components/tor/buildflags", | ||
"//components/resources:components_resources_grit", | ||
"//components/strings:components_strings", | ||
"//third_party/re2", | ||
"//ui/base:base", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include_rules = [ | ||
"+third_party/re2", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "brave/components/webui/about_ui.h" | ||
|
||
#include <string_view> | ||
|
||
#include "base/containers/contains.h" | ||
#include "base/containers/fixed_flat_set.h" | ||
#include "base/strings/string_split.h" | ||
#include "base/strings/string_util.h" | ||
#include "third_party/re2/src/re2/re2.h" | ||
|
||
namespace brave { | ||
|
||
std::string ReplaceAboutUIChromeURLs(std::string chrome_urls) { | ||
// Replace Chrome -> Brave. | ||
constexpr std::string_view kChromeHeader = "Chrome URLs"; | ||
constexpr std::string_view kBraveHeader = "Brave URLs"; | ||
constexpr std::string_view kChromePagesHeader = "List of Chrome URLs"; | ||
constexpr std::string_view kBravePagesHeader = "List of Brave URLs"; | ||
constexpr std::string_view kChromeInternalPagesHeader = | ||
"List of chrome://internals pages"; | ||
constexpr std::string_view kBraveInternalPagesHeader = | ||
"List of brave://internals pages"; | ||
constexpr std::string_view kChromeURLList = ">chrome://"; | ||
constexpr std::string_view kBraveURLList = ">brave://"; | ||
|
||
RE2::GlobalReplace(&chrome_urls, kChromeHeader, kBraveHeader); | ||
RE2::GlobalReplace(&chrome_urls, kChromePagesHeader, kBravePagesHeader); | ||
RE2::GlobalReplace(&chrome_urls, kChromeInternalPagesHeader, | ||
kBraveInternalPagesHeader); | ||
RE2::GlobalReplace(&chrome_urls, kChromeURLList, kBraveURLList); | ||
|
||
// Remove some URLs. | ||
auto html_lines = base::SplitStringPiece( | ||
chrome_urls, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | ||
constexpr auto kURLsToRemove = base::MakeFixedFlatSet<std::string_view>({ | ||
"brave://memories", | ||
}); | ||
// URLs in html should be sorted so it's okay to iterate over sorted | ||
// kURLsToRemove. | ||
auto html_line_it = html_lines.begin(); | ||
auto* url_to_remove_it = kURLsToRemove.begin(); | ||
while (html_line_it != html_lines.end() && | ||
url_to_remove_it != kURLsToRemove.end()) { | ||
if (base::Contains(*html_line_it, *url_to_remove_it)) { | ||
html_line_it = html_lines.erase(html_line_it); | ||
++url_to_remove_it; | ||
} else { | ||
++html_line_it; | ||
} | ||
} | ||
|
||
return base::JoinString(html_lines, "\n"); | ||
} | ||
|
||
} // namespace brave |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#ifndef BRAVE_COMPONENTS_WEBUI_ABOUT_UI_H_ | ||
#define BRAVE_COMPONENTS_WEBUI_ABOUT_UI_H_ | ||
|
||
#include <string> | ||
|
||
namespace brave { | ||
|
||
std::string ReplaceAboutUIChromeURLs(std::string chrome_urls); | ||
|
||
} // namespace brave | ||
|
||
#endif // BRAVE_COMPONENTS_WEBUI_ABOUT_UI_H_ |
Oops, something went wrong.