Skip to content

[iOS] Use Chromium web embedder (CWVWebView) #24657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions chromium_src/ios/CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Common linting false posititives from Obj-C syntax in headers
filter=-readability/casting,-whitespace/parens,-whitespace/operators
4 changes: 4 additions & 0 deletions chromium_src/ios/chrome/browser/https_upgrades/model/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include_rules = [
"+brave/components/https_upgrade_exceptions/browser",
"+brave/ios/browser/application_context",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2024 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/https_upgrade_exceptions/browser/https_upgrade_exceptions_service.h"
#include "brave/ios/browser/application_context/brave_application_context_impl.h"
#import "ios/chrome/browser/shared/model/prefs/pref_names.h"
#import "ios/components/security_interstitials/https_only_mode/feature.h"
#import "ios/components/security_interstitials/https_only_mode/https_upgrade_service.h"
#include "net/base/features.h"
#include "net/base/url_util.h"

namespace {
bool CanUpgradeToHTTPS(const GURL& url) {
// FIXME: Move this impl out of the chromium_src override
BraveApplicationContextImpl* braveContext =
static_cast<BraveApplicationContextImpl*>(GetApplicationContext());
return braveContext->https_upgrade_exceptions_service()->CanUpgradeToHTTPS(
url);
}
} // namespace

// Add checks for Brave-by-default feature flag, standard HTTPS upgrades pref
// and the brave https upgrade exception list when determining if the navigation
// should be upgraded
#define kHttpsUpgrades kHttpsUpgrades) && \
!base::FeatureList::IsEnabled(net::features::kBraveHttpsByDefault) && \
!(prefs_ && prefs_->GetBoolean(prefs::kHttpsUpgradesEnabled)
#define IsLocalhost IsLocalhost(url) || !CanUpgradeToHTTPS
#include "src/ios/chrome/browser/https_upgrades/model/https_only_mode_upgrade_tab_helper.mm"
#undef IsLocalhost
#undef kHttpsUpgrades
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
#include "ios/chrome/browser/profile/model/keyed_service_factories.h"

#include "brave/ios/browser/profile/model/brave_keyed_service_factories.h"
#include "ios/chrome/browser/affiliations/model/ios_chrome_affiliation_service_factory.h"
#include "ios/chrome/browser/autocomplete/model/autocomplete_classifier_factory.h"
#include "ios/chrome/browser/autocomplete/model/zero_suggest_cache_service_factory.h"
#include "ios/chrome/browser/autofill/model/autofill_log_router_factory.h"
#include "ios/chrome/browser/autofill/model/personal_data_manager_factory.h"
#include "ios/chrome/browser/bookmarks/model/account_bookmark_sync_service_factory.h"
#include "ios/chrome/browser/bookmarks/model/bookmark_model_factory.h"
#include "ios/chrome/browser/bookmarks/model/bookmark_undo_service_factory.h"
#include "ios/chrome/browser/bookmarks/model/local_or_syncable_bookmark_sync_service_factory.h"
#include "ios/chrome/browser/browsing_data/model/browsing_data_remover_factory.h"
#include "ios/chrome/browser/consent_auditor/model/consent_auditor_factory.h"
#include "ios/chrome/browser/content_settings/model/host_content_settings_map_factory.h"
#include "ios/chrome/browser/credential_provider/model/credential_provider_buildflags.h"
Expand All @@ -22,25 +25,33 @@
#include "ios/chrome/browser/favicon/model/ios_chrome_favicon_loader_factory.h"
#include "ios/chrome/browser/favicon/model/ios_chrome_large_icon_cache_factory.h"
#include "ios/chrome/browser/favicon/model/ios_chrome_large_icon_service_factory.h"
#include "ios/chrome/browser/gcm/model/ios_chrome_gcm_profile_service_factory.h"
#include "ios/chrome/browser/history/model/history_service_factory.h"
#include "ios/chrome/browser/history/model/top_sites_factory.h"
#include "ios/chrome/browser/history/model/web_history_service_factory.h"
#include "ios/chrome/browser/https_upgrades/model/https_upgrade_service_factory.h"
#include "ios/chrome/browser/invalidation/model/ios_chrome_profile_invalidation_provider_factory.h"
#include "ios/chrome/browser/language/model/accept_languages_service_factory.h"
#include "ios/chrome/browser/language/model/language_model_manager_factory.h"
#include "ios/chrome/browser/language/model/url_language_histogram_factory.h"
#include "ios/chrome/browser/metrics/model/google_groups_manager_factory.h"
#include "ios/chrome/browser/optimization_guide/model/optimization_guide_service_factory.h"
#include "ios/chrome/browser/page_info/about_this_site_service_factory.h"
#include "ios/chrome/browser/passwords/model/ios_chrome_account_password_store_factory.h"
#include "ios/chrome/browser/passwords/model/ios_chrome_bulk_leak_check_service_factory.h"
#include "ios/chrome/browser/passwords/model/ios_chrome_password_receiver_service_factory.h"
#include "ios/chrome/browser/passwords/model/ios_chrome_password_reuse_manager_factory.h"
#include "ios/chrome/browser/passwords/model/ios_chrome_password_sender_service_factory.h"
#include "ios/chrome/browser/passwords/model/ios_chrome_profile_password_store_factory.h"
#include "ios/chrome/browser/passwords/model/ios_password_manager_settings_service_factory.h"
#include "ios/chrome/browser/passwords/model/ios_password_requirements_service_factory.h"
#include "ios/chrome/browser/passwords/model/password_manager_log_router_factory.h"
#include "ios/chrome/browser/plus_addresses/model/plus_address_service_factory.h"
#include "ios/chrome/browser/plus_addresses/model/plus_address_setting_service_factory.h"
#include "ios/chrome/browser/power_bookmarks/model/power_bookmark_service_factory.h"
#include "ios/chrome/browser/push_notification/model/push_notification_profile_service_factory.h"
#include "ios/chrome/browser/reading_list/model/reading_list_model_factory.h"
#include "ios/chrome/browser/safe_browsing/model/safe_browsing_client_factory.h"
#include "ios/chrome/browser/safe_browsing/model/safe_browsing_metrics_collector_factory.h"
#include "ios/chrome/browser/saved_tab_groups/model/tab_group_sync_service_factory.h"
#include "ios/chrome/browser/search_engines/model/template_url_service_factory.h"
Expand All @@ -50,6 +61,7 @@
#include "ios/chrome/browser/signin/model/account_consistency_service_factory.h"
#include "ios/chrome/browser/signin/model/account_reconcilor_factory.h"
#include "ios/chrome/browser/signin/model/identity_manager_factory.h"
#include "ios/chrome/browser/signin/model/signin_client_factory.h"
#include "ios/chrome/browser/supervised_user/model/child_account_service_factory.h"
#include "ios/chrome/browser/supervised_user/model/list_family_members_service_factory.h"
#include "ios/chrome/browser/supervised_user/model/supervised_user_service_factory.h"
Expand All @@ -70,47 +82,56 @@
#endif

void EnsureProfileKeyedServiceFactoriesBuilt() {
autofill::AutofillLogRouterFactory::GetInstance();
autofill::PersonalDataManagerFactory::GetInstance();
data_sharing::DataSharingServiceFactory::GetInstance();
ios::AccountBookmarkSyncServiceFactory::GetInstance();
ios::AccountConsistencyServiceFactory::GetInstance();
ios::AccountReconcilorFactory::GetInstance();
ios::AutocompleteClassifierFactory::GetInstance();
ios::BookmarkModelFactory::GetInstance();
ios::BookmarkUndoServiceFactory::GetInstance();
ios::FaviconServiceFactory::GetInstance();
ios::HistoryServiceFactory::GetInstance();
ios::LocalOrSyncableBookmarkSyncServiceFactory::GetInstance();
ios::TopSitesFactory::GetInstance();
ios::AutocompleteClassifierFactory::GetInstance();
ios::HostContentSettingsMapFactory::GetInstance();
ios::LocalOrSyncableBookmarkSyncServiceFactory::GetInstance();
ios::PasswordManagerLogRouterFactory::GetInstance();
ios::TemplateURLServiceFactory::GetInstance();
ios::TopSitesFactory::GetInstance();
ios::WebDataServiceFactory::GetInstance();
ios::WebHistoryServiceFactory::GetInstance();
ios::ZeroSuggestCacheServiceFactory::GetInstance();
segmentation_platform::SegmentationPlatformServiceFactory::GetInstance();
tab_groups::TabGroupSyncServiceFactory::GetInstance();
translate::TranslateRankerFactory::GetInstance();
AboutThisSiteServiceFactory::GetInstance();
AcceptLanguagesServiceFactory::GetInstance();
BackgroundDownloadServiceFactory::GetInstance();
BrowserListFactory::GetInstance();
BrowsingDataRemoverFactory::GetInstance();
ChildAccountServiceFactory::GetInstance();
ConsentAuditorFactory::GetInstance();
DeviceInfoSyncServiceFactory::GetInstance();
GoogleGroupsManagerFactory::GetInstance();
HttpsUpgradeServiceFactory::GetInstance();
IdentityManagerFactory::GetInstance();
IOSChromeAccountPasswordStoreFactory::GetInstance();
IOSChromeAffiliationServiceFactory::GetInstance();
IOSChromeBulkLeakCheckServiceFactory::GetInstance();
IOSChromeFaviconLoaderFactory::GetInstance();
IOSChromeGCMProfileServiceFactory::GetInstance();
IOSChromeLargeIconCacheFactory::GetInstance();
IOSChromeLargeIconServiceFactory::GetInstance();
IOSChromePasswordReceiverServiceFactory::GetInstance();
IOSChromePasswordReuseManagerFactory::GetInstance();
IOSChromePasswordSenderServiceFactory::GetInstance();
IOSChromeProfilePasswordStoreFactory::GetInstance();
IOSChromeProfileInvalidationProviderFactory::GetInstance();
IOSChromeProfilePasswordStoreFactory::GetInstance();
IOSPasskeyModelFactory::GetInstance();
IOSPasswordManagerSettingsServiceFactory::GetInstance();
IOSPasswordRequirementsServiceFactory::GetInstance();
IOSUserEventServiceFactory::GetInstance();
HttpsUpgradeServiceFactory::GetInstance();
LanguageModelManagerFactory::GetInstance();
ListFamilyMembersServiceFactory::GetInstance();
OptimizationGuideServiceFactory::GetInstance();
DataTypeStoreServiceFactory::GetInstance();
Expand All @@ -122,11 +143,17 @@ void EnsureProfileKeyedServiceFactoriesBuilt() {
SyncServiceFactory::GetInstance();
UnifiedConsentServiceFactory::GetInstance();
ReadingListModelFactory::GetInstance();
SafeBrowsingClientFactory::GetInstance();
SafeBrowsingMetricsCollectorFactory::GetInstance();
SendTabToSelfSyncServiceFactory::GetInstance();
SessionRestorationServiceFactory::GetInstance();
SessionSyncServiceFactory::GetInstance();
SigninClientFactory::GetInstance();
SupervisedUserServiceFactory::GetInstance();
SupervisedUserSettingsServiceFactory::GetInstance();
SyncServiceFactory::GetInstance();
UnifiedConsentServiceFactory::GetInstance();
UrlLanguageHistogramFactory::GetInstance();

#if BUILDFLAG(IOS_CREDENTIAL_PROVIDER_ENABLED)
CredentialProviderServiceFactory::GetInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "brave/components/skus/browser/skus_utils.h"
#include "brave/ios/browser/brave_stats/brave_stats_prefs.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "ios/chrome/browser/shared/model/prefs/pref_names.h"

void BraveRegisterBrowserStatePrefs(
user_prefs::PrefRegistrySyncable* registry) {
Expand All @@ -42,6 +43,8 @@ void BraveRegisterBrowserStatePrefs(
ai_chat::ModelService::RegisterProfilePrefs(registry);
omnibox::RegisterBraveProfilePrefs(registry);
brave_news::prefs::RegisterProfilePrefs(registry);

registry->RegisterBooleanPref(prefs::kHttpsUpgradesEnabled, true);
}

void BraveRegisterLocalStatePrefs(PrefRegistrySimple* registry) {
Expand Down
16 changes: 16 additions & 0 deletions chromium_src/ios/chrome/browser/shared/model/prefs/pref_names.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2024 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_CHROMIUM_SRC_IOS_CHROME_BROWSER_SHARED_MODEL_PREFS_PREF_NAMES_H_
#define BRAVE_CHROMIUM_SRC_IOS_CHROME_BROWSER_SHARED_MODEL_PREFS_PREF_NAMES_H_

#include "src/ios/chrome/browser/shared/model/prefs/pref_names.h" // IWYU pragma: export

namespace prefs {
// A boolean specifying whether HTTPS Upgrades are enabled.
inline constexpr char kHttpsUpgradesEnabled[] = "ios.https_upgrades_enabled";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we normally wouldn't put this kind of stuff in a chromium_src override, but it appears that we're doing that quite a bit already in ios. We shouldn't use chromium_src overrides as a replacement for brave code that should go under ios. So for instance above in BraveRegisterBrowserStatePrefs should really go in ios/brave/browser/shared/model/prefs/browser_prefs.mm and same here.

} // namespace prefs

#endif // BRAVE_CHROMIUM_SRC_IOS_CHROME_BROWSER_SHARED_MODEL_PREFS_PREF_NAMES_H_
34 changes: 33 additions & 1 deletion chromium_src/ios/chrome/browser/tabs/model/tab_helper_util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,46 @@

#import "ios/chrome/browser/tabs/model/tab_helper_util.h"

#import "components/omnibox/common/omnibox_features.h"
#include "ios/chrome/browser/complex_tasks/model/ios_task_tab_helper.h"
#import "ios/chrome/browser/https_upgrades/model/https_only_mode_upgrade_tab_helper.h"
#import "ios/chrome/browser/https_upgrades/model/https_upgrade_service_factory.h"
#import "ios/chrome/browser/https_upgrades/model/typed_navigation_upgrade_tab_helper.h"
#import "ios/chrome/browser/prerender/model/prerender_service_factory.h"
#include "ios/chrome/browser/sessions/model/ios_chrome_session_tab_helper.h"
#import "ios/chrome/browser/sessions/model/web_session_state_tab_helper.h"
#include "ios/chrome/browser/sessions/model/web_session_state_tab_helper.h"
#import "ios/chrome/browser/shared/model/profile/profile_ios.h"
#include "ios/chrome/browser/tabs/model/ios_chrome_synced_tab_delegate.h"
#import "ios/components/security_interstitials/https_only_mode/feature.h"
#import "ios/components/security_interstitials/https_only_mode/https_only_mode_container.h"
#import "ios/components/security_interstitials/ios_blocking_page_tab_helper.h"

void AttachTabHelpers(web::WebState* web_state, TabHelperFilter filter_flags) {
ProfileIOS* const profile =
ProfileIOS::FromBrowserState(web_state->GetBrowserState());

IOSChromeSessionTabHelper::CreateForWebState(web_state);
IOSChromeSyncedTabDelegate::CreateForWebState(web_state);
WebSessionStateTabHelper::CreateForWebState(web_state);
IOSTaskTabHelper::CreateForWebState(web_state);

security_interstitials::IOSBlockingPageTabHelper::CreateForWebState(
web_state);

if (base::FeatureList::IsEnabled(
security_interstitials::features::kHttpsOnlyMode) ||
base::FeatureList::IsEnabled(
security_interstitials::features::kHttpsUpgrades)) {
HttpsOnlyModeUpgradeTabHelper::CreateForWebState(
web_state, profile->GetPrefs(),
PrerenderServiceFactory::GetForProfile(profile),
HttpsUpgradeServiceFactory::GetForProfile(profile));
HttpsOnlyModeContainer::CreateForWebState(web_state);
}

if (base::FeatureList::IsEnabled(omnibox::kDefaultTypedNavigationsToHttps)) {
TypedNavigationUpgradeTabHelper::CreateForWebState(
web_state, PrerenderServiceFactory::GetForProfile(profile),
HttpsUpgradeServiceFactory::GetForProfile(profile));
}
}
Loading
Loading