-
Notifications
You must be signed in to change notification settings - Fork 899
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add clean copy url service interface for iOS (uplift to 1.58.x) (#20017)
Add clean copy url service interface for iOS (#19079) Co-authored-by: bridiver <[email protected]>
- Loading branch information
Showing
21 changed files
with
480 additions
and
6 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
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
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,20 @@ | ||
# 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/. | ||
|
||
source_set("url_sanitizer") { | ||
configs += [ "//build/config/compiler:enable_arc" ] | ||
sources = [ | ||
"url_sanitizer_service+private.h", | ||
"url_sanitizer_service.h", | ||
"url_sanitizer_service.mm", | ||
] | ||
deps = [ | ||
"//base", | ||
"//brave/components/url_sanitizer/browser", | ||
"//net", | ||
"//url", | ||
] | ||
frameworks = [ "Foundation.framework" ] | ||
} |
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,7 @@ | ||
# 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/. | ||
|
||
browser_api_url_sanitizer_public_headers = | ||
[ "//brave/ios/browser/api/url_sanitizer/url_sanitizer_service.h" ] |
26 changes: 26 additions & 0 deletions
26
ios/browser/api/url_sanitizer/url_sanitizer_service+private.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,26 @@ | ||
// 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_IOS_BROWSER_API_URL_SANITIZER_URL_SANITIZER_SERVICE_PRIVATE_H_ | ||
#define BRAVE_IOS_BROWSER_API_URL_SANITIZER_URL_SANITIZER_SERVICE_PRIVATE_H_ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#include "base/memory/raw_ptr.h" | ||
#include "brave/components/url_sanitizer/browser/url_sanitizer_service.h" | ||
#include "brave/ios/browser/api/url_sanitizer/url_sanitizer_service.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface URLSanitizerService (Private) | ||
|
||
- (instancetype)initWithURLSanitizerService: | ||
(brave::URLSanitizerService*)urlSanitizer; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
||
#endif // BRAVE_IOS_BROWSER_API_URL_SANITIZER_URL_SANITIZER_SERVICE_PRIVATE_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,29 @@ | ||
// 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_IOS_BROWSER_API_URL_SANITIZER_URL_SANITIZER_SERVICE_H_ | ||
#define BRAVE_IOS_BROWSER_API_URL_SANITIZER_URL_SANITIZER_SERVICE_H_ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
OBJC_EXPORT | ||
@interface URLSanitizerService : NSObject | ||
- (instancetype)init NS_UNAVAILABLE; | ||
|
||
/** | ||
Sanitizes the given URL. | ||
@param url The URL to be sanitized. | ||
@return A sanitized NSURL object. | ||
*/ | ||
- (nullable NSURL*)sanitizeURL:(NSURL*)url; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
||
#endif // BRAVE_IOS_BROWSER_API_URL_SANITIZER_URL_SANITIZER_SERVICE_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,39 @@ | ||
// 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/ios/browser/api/url_sanitizer/url_sanitizer_service+private.h" | ||
|
||
#include <string> | ||
|
||
#include "base/memory/raw_ptr.h" | ||
#include "brave/components/url_sanitizer/browser/url_sanitizer_service.h" | ||
#import "net/base/mac/url_conversions.h" | ||
#include "url/gurl.h" | ||
|
||
@interface URLSanitizerService () { | ||
raw_ptr<brave::URLSanitizerService> urlSanitizer_; // NOT OWNED | ||
} | ||
|
||
@end | ||
|
||
@implementation URLSanitizerService | ||
|
||
- (instancetype)initWithURLSanitizerService: | ||
(brave::URLSanitizerService*)urlSanitizer { | ||
self = [super init]; | ||
if (self) { | ||
urlSanitizer_ = urlSanitizer; | ||
} | ||
return self; | ||
} | ||
|
||
- (nullable NSURL*)sanitizeURL:(NSURL*)url { | ||
DCHECK(urlSanitizer_); | ||
GURL gurl = net::GURLWithNSURL(url); | ||
GURL cleanURL = urlSanitizer_->SanitizeURL(gurl); | ||
return net::NSURLWithGURL(cleanURL); | ||
} | ||
|
||
@end |
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,21 @@ | ||
# 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("//build/config/ios/rules.gni") | ||
import("//ios/build/config.gni") | ||
|
||
source_set("application_context") { | ||
sources = [ | ||
"brave_application_context_impl.h", | ||
"brave_application_context_impl.mm", | ||
] | ||
deps = [ | ||
"//base", | ||
"//brave/components/brave_component_updater/browser", | ||
"//brave/components/url_sanitizer/browser", | ||
"//ios/chrome/browser/application_context", | ||
"//ios/chrome/browser/shared/model/application_context", | ||
] | ||
} |
57 changes: 57 additions & 0 deletions
57
ios/browser/application_context/brave_application_context_impl.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,57 @@ | ||
// 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_IOS_BROWSER_APPLICATION_CONTEXT_BRAVE_APPLICATION_CONTEXT_IMPL_H_ | ||
#define BRAVE_IOS_BROWSER_APPLICATION_CONTEXT_BRAVE_APPLICATION_CONTEXT_IMPL_H_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "brave/components/brave_component_updater/browser/brave_component.h" | ||
#include "brave/components/url_sanitizer/browser/url_sanitizer_component_installer.h" | ||
#include "ios/chrome/browser/application_context/application_context_impl.h" | ||
|
||
namespace base { | ||
class CommandLine; | ||
class SequencedTaskRunner; | ||
} // namespace base | ||
|
||
/// This extends the behaviors of the ApplicationContext | ||
class BraveApplicationContextImpl : public ApplicationContextImpl { | ||
public: | ||
// Out-of-line constructor declaration | ||
BraveApplicationContextImpl( | ||
base::SequencedTaskRunner* local_state_task_runner, | ||
const base::CommandLine& command_line, | ||
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; | ||
|
||
// 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(); | ||
brave_component_updater::LocalDataFilesService* local_data_files_service(); | ||
|
||
std::unique_ptr<brave_component_updater::BraveComponent::Delegate> | ||
brave_component_updater_delegate_; | ||
std::unique_ptr<brave_component_updater::LocalDataFilesService> | ||
local_data_files_service_; | ||
std::unique_ptr<brave::URLSanitizerComponentInstaller> | ||
url_sanitizer_component_installer_; | ||
}; | ||
|
||
#endif // BRAVE_IOS_BROWSER_APPLICATION_CONTEXT_BRAVE_APPLICATION_CONTEXT_IMPL_H_ |
69 changes: 69 additions & 0 deletions
69
ios/browser/application_context/brave_application_context_impl.mm
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,69 @@ | ||
// 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/ios/browser/application_context/brave_application_context_impl.h" | ||
|
||
#include <string> | ||
|
||
#import "base/command_line.h" | ||
#import "base/task/sequenced_task_runner.h" | ||
#include "brave/components/brave_component_updater/browser/brave_component.h" | ||
#include "brave/components/brave_component_updater/browser/brave_component_updater_delegate.h" | ||
#include "brave/components/brave_component_updater/browser/local_data_files_service.h" | ||
#include "brave/components/url_sanitizer/browser/url_sanitizer_component_installer.h" | ||
#include "ios/chrome/browser/shared/model/application_context/application_context.h" | ||
|
||
BraveApplicationContextImpl::BraveApplicationContextImpl( | ||
base::SequencedTaskRunner* local_state_task_runner, | ||
const base::CommandLine& command_line, | ||
const std::string& locale, | ||
const std::string& country) | ||
: ApplicationContextImpl(local_state_task_runner, | ||
command_line, | ||
locale, | ||
country) {} | ||
|
||
inline BraveApplicationContextImpl::~BraveApplicationContextImpl() = default; | ||
|
||
brave_component_updater::BraveComponent::Delegate* | ||
BraveApplicationContextImpl::brave_component_updater_delegate() { | ||
if (!brave_component_updater_delegate_) { | ||
brave_component_updater_delegate_ = | ||
std::make_unique<brave::BraveComponentUpdaterDelegate>( | ||
GetComponentUpdateService(), GetLocalState(), | ||
GetApplicationLocale()); | ||
} | ||
|
||
return brave_component_updater_delegate_.get(); | ||
} | ||
|
||
brave_component_updater::LocalDataFilesService* | ||
BraveApplicationContextImpl::local_data_files_service() { | ||
if (!local_data_files_service_) { | ||
local_data_files_service_ = | ||
brave_component_updater::LocalDataFilesServiceFactory( | ||
brave_component_updater_delegate()); | ||
} | ||
return local_data_files_service_.get(); | ||
} | ||
|
||
brave::URLSanitizerComponentInstaller* | ||
BraveApplicationContextImpl::url_sanitizer_component_installer() { | ||
if (!url_sanitizer_component_installer_) { | ||
url_sanitizer_component_installer_ = | ||
std::make_unique<brave::URLSanitizerComponentInstaller>( | ||
local_data_files_service()); | ||
} | ||
return url_sanitizer_component_installer_.get(); | ||
} | ||
|
||
void BraveApplicationContextImpl::StartBraveServices() { | ||
// We need to Initialize the component installer | ||
// before calling Start on the local_data_files_service | ||
url_sanitizer_component_installer(); | ||
|
||
// Start the local data file service | ||
local_data_files_service()->Start(); | ||
} |
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
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
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
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
Oops, something went wrong.