Skip to content

Commit

Permalink
Fix #34240: Add WebUI & Expose WebViews to iOS (#20929)
Browse files Browse the repository at this point in the history
- 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
Brandon-T authored Dec 4, 2023
1 parent b56bd7e commit b185762
Show file tree
Hide file tree
Showing 46 changed files with 1,783 additions and 1,337 deletions.
1 change: 1 addition & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ source_set("ui") {
"//brave/components/tor/buildflags",
"//brave/components/url_sanitizer/browser",
"//brave/components/vector_icons",
"//brave/components/webui",
"//chrome/app:command_ids",
"//chrome/app/vector_icons:vector_icons",
"//chrome/browser:browser_process",
Expand Down
814 changes: 7 additions & 807 deletions browser/ui/webui/brave_webui_source.cc

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions chromium_src/chrome/browser/ui/webui/DEPS
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",
]
56 changes: 6 additions & 50 deletions chromium_src/chrome/browser/ui/webui/about_ui.cc
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());
}
5 changes: 5 additions & 0 deletions chromium_src/ios/chrome/browser/ui/webui/DEPS
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",
]
13 changes: 13 additions & 0 deletions chromium_src/ios/chrome/browser/ui/webui/about_ui.cc
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"
11 changes: 11 additions & 0 deletions chromium_src/ios/chrome/browser/ui/webui/crashes_ui.cc
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
11 changes: 11 additions & 0 deletions chromium_src/ios/chrome/browser/ui/webui/version_ui.mm
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
37 changes: 37 additions & 0 deletions components/webui/BUILD.gn
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",
]
}
3 changes: 3 additions & 0 deletions components/webui/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+third_party/re2",
]
60 changes: 60 additions & 0 deletions components/webui/about_ui.cc
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
17 changes: 17 additions & 0 deletions components/webui/about_ui.h
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_
Loading

0 comments on commit b185762

Please sign in to comment.