Skip to content
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

Fix #33746: Cleanup Brave-Core iOS chromium_src overrides & initialization code #20598

Merged
merged 1 commit into from
Oct 20, 2023
Merged
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

This file was deleted.

10 changes: 10 additions & 0 deletions chromium_src/ios/chrome/browser/web/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include_rules = [
"+src/ios/chrome/browser",
]

specific_include_rules = {
"chrome_main_parts\.mm": [
"+brave/ios/browser/application_context/brave_application_context_impl.h",
"+ios/chrome/browser/web/chrome_main_parts.h",
]
}
23 changes: 23 additions & 0 deletions chromium_src/ios/chrome/browser/web/chrome_main_parts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* 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_CHROMIUM_SRC_IOS_CHROME_BROWSER_WEB_CHROME_MAIN_PARTS_H_
#define BRAVE_CHROMIUM_SRC_IOS_CHROME_BROWSER_WEB_CHROME_MAIN_PARTS_H_

#include "ios/web/public/init/web_main_parts.h"

// Change `PreCreateMainMessageLoop` to `protected` so we can override the
// IE: Change all the ChromeMainParts functions to `protected` instead of
// `private.
#define PreCreateMainMessageLoop \
PreCreateMainMessageLoop_ChromiumImpl(); \
\
protected: \
void PreCreateMainMessageLoop

#include "src/ios/chrome/browser/web/chrome_main_parts.h" // IWYU pragma: export
#undef PreCreateMainMessageLoop

#endif // BRAVE_CHROMIUM_SRC_IOS_CHROME_BROWSER_WEB_CHROME_MAIN_PARTS_H_
17 changes: 17 additions & 0 deletions chromium_src/ios/chrome/browser/web/chrome_main_parts.mm
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/. */

#include "ios/chrome/browser/web/chrome_main_parts.h"
#include "brave/ios/browser/application_context/brave_application_context_impl.h"

#define PreCreateMainMessageLoop PreCreateMainMessageLoop_ChromiumImpl
#define ApplicationContextImpl BraveApplicationContextImpl
#include "src/ios/chrome/browser/web/chrome_main_parts.mm"
#undef ApplicationContextImpl
#undef PreCreateMainMessageLoop

void IOSChromeMainParts::PreCreateMainMessageLoop() {
IOSChromeMainParts::PreCreateMainMessageLoop_ChromiumImpl();
}
1 change: 1 addition & 0 deletions ios/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ source_set("browser") {
"//ios/chrome/browser/shared/model/browser_state",
"//ios/chrome/browser/shared/model/paths",
"//ios/chrome/browser/shared/model/url:constants",
"//ios/chrome/browser/web:web_internal",
"//ios/components/webui:url_constants",
"//ios/web/public",
"//ios/web/public/init",
Expand Down
1 change: 1 addition & 0 deletions ios/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include_rules = [
"+components",
"+mojo/public/cpp/bindings",
"+ios/chrome/browser",
"+ios/chrome/browser/web",
"+ios/components",
"+ios/web/public",
"+ios/web/js_messaging",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@ class BraveApplicationContextImpl : public ApplicationContextImpl {
const std::string& locale,
const std::string& country);

brave::URLSanitizerComponentInstaller* url_sanitizer_component_installer();

// Disable copy constructor and assignment operator
BraveApplicationContextImpl(const BraveApplicationContextImpl&) = delete;
BraveApplicationContextImpl& operator=(const BraveApplicationContextImpl&) =
delete;

~BraveApplicationContextImpl() override;

// ApplicationContextImpl
ukm::UkmRecorder* GetUkmRecorder() override;
BrowserPolicyConnectorIOS* GetBrowserPolicyConnector() override;
gcm::GCMDriver* GetGCMDriver() override;

// BraveApplicationContextImpl
brave::URLSanitizerComponentInstaller* url_sanitizer_component_installer();

// Start any services that we may need later
void StartBraveServices();

// Out-of-line destructor declaration
~BraveApplicationContextImpl() override;

private:
brave_component_updater::BraveComponent::Delegate*
brave_component_updater_delegate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@

inline BraveApplicationContextImpl::~BraveApplicationContextImpl() = default;

// MARK: - ApplicationContextImpl

ukm::UkmRecorder* BraveApplicationContextImpl::GetUkmRecorder() {
return nullptr;
}

BrowserPolicyConnectorIOS*
BraveApplicationContextImpl::GetBrowserPolicyConnector() {
return nullptr;
}

gcm::GCMDriver* BraveApplicationContextImpl::GetGCMDriver() {
return nullptr;
}

// MARK: - BraveApplicationContextImpl

brave_component_updater::BraveComponent::Delegate*
BraveApplicationContextImpl::brave_component_updater_delegate() {
if (!brave_component_updater_delegate_) {
Expand Down
19 changes: 2 additions & 17 deletions ios/browser/brave_web_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@

#include <memory>
#include <string>
#include <string_view>
#include <vector>

#include "base/compiler_specific.h"
#import "ios/web/public/web_client.h"
#include "ios/chrome/browser/web/chrome_web_client.h"

class BraveWebMainParts;

class BraveWebClient : public web::WebClient {
class BraveWebClient : public ChromeWebClient {
public:
BraveWebClient();
BraveWebClient(const BraveWebClient&) = delete;
Expand All @@ -26,21 +22,10 @@ class BraveWebClient : public web::WebClient {
void SetUserAgent(const std::string& user_agent);

// WebClient implementation.
void AddAdditionalSchemes(Schemes* schemes) const override;
bool IsAppSpecificURL(const GURL& url) const override;

std::unique_ptr<web::WebMainParts> CreateWebMainParts() override;
std::string GetUserAgent(web::UserAgentType type) const override;
std::string_view GetDataResource(
int resource_id,
ui::ResourceScaleFactor scale_factor) const override;
base::RefCountedMemory* GetDataResourceBytes(int resource_id) const override;

void GetAdditionalWebUISchemes(
std::vector<std::string>* additional_schemes) override;

private:
BraveWebMainParts* web_main_parts_;
std::string user_agent_;
};

Expand Down
36 changes: 3 additions & 33 deletions ios/browser/brave_web_client.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,24 @@

#import "brave/ios/browser/brave_web_client.h"

#include <string>
#include <string_view>

#include "base/functional/bind.h"
#include "brave/ios/browser/brave_web_main_parts.h"
#include "ios/chrome/browser/shared/model/url/chrome_url_constants.h"
#include "ios/components/webui/web_ui_url_constants.h"
#include "ui/base/resource/resource_bundle.h"
#include "url/gurl.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif

BraveWebClient::BraveWebClient() : web_main_parts_(nullptr) {}
BraveWebClient::BraveWebClient() {}

BraveWebClient::~BraveWebClient() {
}

void BraveWebClient::AddAdditionalSchemes(Schemes* schemes) const {
schemes->standard_schemes.push_back(kChromeUIScheme);
schemes->secure_schemes.push_back(kChromeUIScheme);
}

bool BraveWebClient::IsAppSpecificURL(const GURL& url) const {
return url.SchemeIs(kChromeUIScheme);
}

std::unique_ptr<web::WebMainParts> BraveWebClient::CreateWebMainParts() {
auto web_main_parts = std::make_unique<BraveWebMainParts>();
web_main_parts_ = web_main_parts.get();
return web_main_parts;
return std::make_unique<BraveWebMainParts>(
*base::CommandLine::ForCurrentProcess());
}

void BraveWebClient::SetUserAgent(const std::string& user_agent) {
Expand All @@ -46,19 +32,3 @@
std::string BraveWebClient::GetUserAgent(web::UserAgentType type) const {
return user_agent_;
}

std::string_view BraveWebClient::GetDataResource(
int resource_id,
ui::ResourceScaleFactor scale_factor) const {
return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
resource_id, scale_factor);
}

base::RefCountedMemory* BraveWebClient::GetDataResourceBytes(
int resource_id) const {
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
resource_id);
}

void BraveWebClient::GetAdditionalWebUISchemes(
std::vector<std::string>* additional_schemes) {}
32 changes: 3 additions & 29 deletions ios/browser/brave_web_main_parts.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,19 @@
#ifndef BRAVE_IOS_BROWSER_BRAVE_WEB_MAIN_PARTS_H_
#define BRAVE_IOS_BROWSER_BRAVE_WEB_MAIN_PARTS_H_

#include <memory>
#include "ios/chrome/browser/web/chrome_main_parts.h"

#include "ios/chrome/browser/flags/ios_chrome_field_trials.h"
#include "ios/web/public/init/web_main_parts.h"

class BraveApplicationContextImpl;
class PrefService;

namespace base {
class FieldTrialList;
}

class BraveWebMainParts : public web::WebMainParts {
class BraveWebMainParts : public IOSChromeMainParts {
public:
BraveWebMainParts();
explicit BraveWebMainParts(const base::CommandLine& parsed_command_line);
BraveWebMainParts(const BraveWebMainParts&) = delete;
BraveWebMainParts& operator=(const BraveWebMainParts&) = delete;
~BraveWebMainParts() override;

private:
void SetupMetrics();
// web::WebMainParts implementation.
void PreCreateMainMessageLoop() override;
void PreCreateThreads() override;
void PreMainMessageLoopRun() override;
void PostMainMessageLoopRun() override;
void PostDestroyThreads() override;
void PostCreateThreads() override;
void SetupFieldTrials();

std::unique_ptr<BraveApplicationContextImpl> application_context_;

// Statistical testing infrastructure for the entire browser. NULL until
// SetUpMetricsAndFieldTrials is called.
std::unique_ptr<base::FieldTrialList> field_trial_list_;

PrefService* local_state_;

IOSChromeFieldTrials ios_field_trials_;
};

#endif // BRAVE_IOS_BROWSER_BRAVE_WEB_MAIN_PARTS_H_
Loading