Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ios: Implement IOSContentMainRunner on content.
Support basic RunContentProcess implementation. Change-Id: I476f71def35d3ba42d73b8b92c68d4856e2a19ee Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4343473 Reviewed-by: Scott Violet <sky@chromium.org> Reviewed-by: Avi Drissman <avi@chromium.org> Reviewed-by: Rohit Rao <rohitrao@chromium.org> Commit-Queue: Avi Drissman <avi@chromium.org> Reviewed-by: Mike Taylor <miketaylr@chromium.org> Cr-Commit-Position: refs/heads/main@{#1118778}
- Loading branch information
Justin Cohen
authored and
Chromium LUCI CQ
committed
Mar 17, 2023
1 parent
40b4bfc
commit 15059b8
Showing
14 changed files
with
561 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2023 The Chromium Authors | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
source_set("init") { | ||
sources = [ | ||
"ios_browser_main_parts.h", | ||
"ios_browser_main_parts.mm", | ||
"ios_content_browser_client.cc", | ||
"ios_content_browser_client.h", | ||
"ios_content_client.cc", | ||
"ios_content_client.h", | ||
"ios_content_main_runner.cc", | ||
"ios_content_main_runner.h", | ||
"ios_main_delegate.cc", | ||
"ios_main_delegate.h", | ||
] | ||
|
||
configs += [ "//build/config/compiler:enable_arc" ] | ||
|
||
deps = [ | ||
"//build:blink_buildflags", | ||
"//components/embedder_support:browser_util", | ||
"//components/embedder_support/origin_trials:origin_trials", | ||
"//components/version_info", | ||
"//content/public/app", | ||
"//content/public/browser", | ||
"//content/public/common/", | ||
"//content/public/renderer", | ||
"//ios/web/public", | ||
"//ios/web/public/init", | ||
] | ||
} |
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,8 @@ | ||
include_rules = [ | ||
"+content/public/app", | ||
"+content/public/browser", | ||
"+content/public/common", | ||
"+content/public/renderer", | ||
"+components/embedder_support", | ||
"+components/version_info", | ||
] |
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,40 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef IOS_WEB_CONTENT_INIT_IOS_BROWSER_MAIN_PARTS_H_ | ||
#define IOS_WEB_CONTENT_INIT_IOS_BROWSER_MAIN_PARTS_H_ | ||
|
||
#import "build/blink_buildflags.h" | ||
#import "content/public/browser/browser_main_parts.h" | ||
|
||
#if !BUILDFLAG(USE_BLINK) | ||
#error File can only be included when USE_BLINK is true | ||
#endif | ||
|
||
namespace web { | ||
|
||
class WebMainParts; | ||
|
||
class IOSBrowserMainParts : public content::BrowserMainParts { | ||
public: | ||
IOSBrowserMainParts(); | ||
IOSBrowserMainParts(const IOSBrowserMainParts&) = delete; | ||
IOSBrowserMainParts& operator=(const IOSBrowserMainParts&) = delete; | ||
~IOSBrowserMainParts() override; | ||
|
||
// BrowserMainParts implementation: | ||
int PreEarlyInitialization() override; | ||
void PostEarlyInitialization() override; | ||
void PreCreateMainMessageLoop() override; | ||
void PostCreateMainMessageLoop() override; | ||
int PreCreateThreads() override; | ||
int PreMainMessageLoopRun() override; | ||
|
||
private: | ||
std::unique_ptr<web::WebMainParts> parts_; | ||
}; | ||
|
||
} // namespace web | ||
|
||
#endif // IOS_WEB_CONTENT_INIT_IOS_BROWSER_MAIN_PARTS_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,44 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "ios/web/content/init/ios_browser_main_parts.h" | ||
|
||
#import "ios/web/public/init/web_main_parts.h" | ||
#import "ios/web/public/web_client.h" | ||
|
||
#if !defined(__has_feature) || !__has_feature(objc_arc) | ||
#error "This file requires ARC support." | ||
#endif | ||
|
||
namespace web { | ||
|
||
IOSBrowserMainParts::IOSBrowserMainParts() { | ||
parts_ = web::GetWebClient()->CreateWebMainParts(); | ||
} | ||
|
||
IOSBrowserMainParts::~IOSBrowserMainParts() {} | ||
|
||
int IOSBrowserMainParts::PreEarlyInitialization() { | ||
parts_->PreEarlyInitialization(); | ||
return 0; | ||
} | ||
void IOSBrowserMainParts::PostEarlyInitialization() { | ||
parts_->PostEarlyInitialization(); | ||
} | ||
void IOSBrowserMainParts::PreCreateMainMessageLoop() { | ||
parts_->PreCreateMainMessageLoop(); | ||
} | ||
void IOSBrowserMainParts::PostCreateMainMessageLoop() { | ||
parts_->PostCreateMainMessageLoop(); | ||
} | ||
int IOSBrowserMainParts::PreCreateThreads() { | ||
parts_->PreCreateThreads(); | ||
return 0; | ||
} | ||
int IOSBrowserMainParts::PreMainMessageLoopRun() { | ||
parts_->PreMainMessageLoopRun(); | ||
return 0; | ||
} | ||
|
||
} // namespace web |
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,120 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ios/web/content/init/ios_content_browser_client.h" | ||
|
||
#import "components/embedder_support/user_agent_utils.h" | ||
#import "components/version_info/version_info.h" | ||
#import "content/public/browser/browser_context.h" | ||
#import "content/public/browser/devtools_manager_delegate.h" | ||
#import "content/public/common/url_constants.h" | ||
#import "content/public/common/user_agent.h" | ||
#import "ios/web/content/init/ios_browser_main_parts.h" | ||
|
||
namespace web { | ||
|
||
bool IOSContentBrowserClient::IsHandledURL(const GURL& url) { | ||
if (!url.is_valid()) { | ||
return false; | ||
} | ||
static const char* const kProtocolList[] = { | ||
url::kHttpScheme, | ||
url::kHttpsScheme, | ||
url::kWsScheme, | ||
url::kWssScheme, | ||
url::kBlobScheme, | ||
url::kFileSystemScheme, | ||
content::kChromeUIScheme, | ||
content::kChromeUIUntrustedScheme, | ||
content::kChromeDevToolsScheme, | ||
url::kDataScheme, | ||
url::kFileScheme, | ||
}; | ||
for (const char* supported_protocol : kProtocolList) { | ||
if (url.scheme_piece() == supported_protocol) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
std::unique_ptr<content::BrowserMainParts> | ||
IOSContentBrowserClient::CreateBrowserMainParts(bool is_integration_test) { | ||
return std::make_unique<IOSBrowserMainParts>(); | ||
} | ||
|
||
std::string IOSContentBrowserClient::GetAcceptLangs( | ||
content::BrowserContext* context) { | ||
return "en-us,en"; | ||
} | ||
|
||
std::string IOSContentBrowserClient::GetProduct() { | ||
return version_info::GetProductNameAndVersionForUserAgent(); | ||
} | ||
|
||
std::string IOSContentBrowserClient::GetUserAgent() { | ||
return embedder_support::GetUserAgent(); | ||
} | ||
|
||
std::string IOSContentBrowserClient::GetUserAgentBasedOnPolicy( | ||
content::BrowserContext* context) { | ||
return GetUserAgent(); | ||
} | ||
|
||
std::string IOSContentBrowserClient::GetFullUserAgent() { | ||
return embedder_support::GetFullUserAgent(); | ||
} | ||
|
||
std::string IOSContentBrowserClient::GetReducedUserAgent() { | ||
return embedder_support::GetReducedUserAgent(); | ||
} | ||
|
||
blink::UserAgentMetadata IOSContentBrowserClient::GetUserAgentMetadata() { | ||
blink::UserAgentMetadata metadata; | ||
|
||
metadata.brand_version_list.emplace_back(version_info::GetProductName(), | ||
"113"); | ||
metadata.brand_full_version_list.emplace_back( | ||
version_info::GetProductName(), version_info::GetVersionNumber()); | ||
metadata.full_version = version_info::GetVersionNumber(); | ||
metadata.platform = "Unknown"; | ||
metadata.architecture = content::GetCpuArchitecture(); | ||
metadata.model = content::BuildModelInfo(); | ||
|
||
metadata.bitness = content::GetCpuBitness(); | ||
metadata.wow64 = content::IsWoW64(); | ||
|
||
return metadata; | ||
} | ||
|
||
bool IOSContentBrowserClient::IsSharedStorageAllowed( | ||
content::BrowserContext* browser_context, | ||
content::RenderFrameHost* rfh, | ||
const url::Origin& top_frame_origin, | ||
const url::Origin& accessing_origin) { | ||
return true; | ||
} | ||
|
||
bool IOSContentBrowserClient::IsSharedStorageSelectURLAllowed( | ||
content::BrowserContext* browser_context, | ||
const url::Origin& top_frame_origin, | ||
const url::Origin& accessing_origin) { | ||
return true; | ||
} | ||
|
||
content::GeneratedCodeCacheSettings | ||
IOSContentBrowserClient::GetGeneratedCodeCacheSettings( | ||
content::BrowserContext* context) { | ||
// If we pass 0 for size, disk_cache will pick a default size using the | ||
// heuristics based on available disk size. These are implemented in | ||
// disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc. | ||
return content::GeneratedCodeCacheSettings(true, 0, context->GetPath()); | ||
} | ||
|
||
std::unique_ptr<content::DevToolsManagerDelegate> | ||
IOSContentBrowserClient::CreateDevToolsManagerDelegate() { | ||
return std::make_unique<content::DevToolsManagerDelegate>(); | ||
} | ||
|
||
} // namespace web |
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,47 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef IOS_WEB_CONTENT_INIT_IOS_CONTENT_BROWSER_CLIENT_H_ | ||
#define IOS_WEB_CONTENT_INIT_IOS_CONTENT_BROWSER_CLIENT_H_ | ||
|
||
#import "build/blink_buildflags.h" | ||
#include "content/public/browser/content_browser_client.h" | ||
|
||
#if !BUILDFLAG(USE_BLINK) | ||
#error File can only be included when USE_BLINK is true | ||
#endif | ||
|
||
namespace web { | ||
|
||
class IOSContentBrowserClient : public content::ContentBrowserClient { | ||
public: | ||
// ContentBrowserClient implementation: | ||
bool IsHandledURL(const GURL& url) override; | ||
std::unique_ptr<content::BrowserMainParts> CreateBrowserMainParts( | ||
bool is_integration_test) override; | ||
std::string GetAcceptLangs(content::BrowserContext* context) override; | ||
std::string GetProduct() override; | ||
std::string GetUserAgent() override; | ||
std::string GetUserAgentBasedOnPolicy( | ||
content::BrowserContext* context) override; | ||
std::string GetFullUserAgent() override; | ||
std::string GetReducedUserAgent() override; | ||
blink::UserAgentMetadata GetUserAgentMetadata() override; | ||
bool IsSharedStorageAllowed(content::BrowserContext* browser_context, | ||
content::RenderFrameHost* rfh, | ||
const url::Origin& top_frame_origin, | ||
const url::Origin& accessing_origin) override; | ||
bool IsSharedStorageSelectURLAllowed( | ||
content::BrowserContext* browser_context, | ||
const url::Origin& top_frame_origin, | ||
const url::Origin& accessing_origin) override; | ||
content::GeneratedCodeCacheSettings GetGeneratedCodeCacheSettings( | ||
content::BrowserContext* context) override; | ||
std::unique_ptr<content::DevToolsManagerDelegate> | ||
CreateDevToolsManagerDelegate() override; | ||
}; | ||
|
||
} // namespace web | ||
|
||
#endif // IOS_WEB_CONTENT_INIT_IOS_CONTENT_BROWSER_CLIENT_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,51 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "ios/web/content/init/ios_content_client.h" | ||
|
||
#import "ui/base/l10n/l10n_util.h" | ||
#import "ui/base/resource/resource_bundle.h" | ||
|
||
namespace web { | ||
|
||
IOSContentClient::IOSContentClient() {} | ||
IOSContentClient::~IOSContentClient() {} | ||
|
||
blink::OriginTrialPolicy* IOSContentClient::GetOriginTrialPolicy() { | ||
return &origin_trial_policy_; | ||
} | ||
std::u16string IOSContentClient::GetLocalizedString(int message_id) { | ||
return l10n_util::GetStringUTF16(message_id); | ||
} | ||
|
||
std::u16string IOSContentClient::GetLocalizedString( | ||
int message_id, | ||
const std::u16string& replacement) { | ||
return l10n_util::GetStringFUTF16(message_id, replacement); | ||
} | ||
|
||
base::StringPiece IOSContentClient::GetDataResource( | ||
int resource_id, | ||
ui::ResourceScaleFactor scale_factor) { | ||
return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( | ||
resource_id, scale_factor); | ||
} | ||
|
||
base::RefCountedMemory* IOSContentClient::GetDataResourceBytes( | ||
int resource_id) { | ||
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | ||
resource_id); | ||
} | ||
|
||
std::string IOSContentClient::GetDataResourceString(int resource_id) { | ||
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceString( | ||
resource_id); | ||
} | ||
|
||
gfx::Image& IOSContentClient::GetNativeImageNamed(int resource_id) { | ||
return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( | ||
resource_id); | ||
} | ||
|
||
} // namespace web |
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,43 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef IOS_WEB_CONTENT_INIT_IOS_CONTENT_CLIENT_H_ | ||
#define IOS_WEB_CONTENT_INIT_IOS_CONTENT_CLIENT_H_ | ||
|
||
#import "build/blink_buildflags.h" | ||
#import "components/embedder_support/origin_trials/origin_trial_policy_impl.h" | ||
#import "content/public/common/content_client.h" | ||
|
||
#if !BUILDFLAG(USE_BLINK) | ||
#error File can only be included when USE_BLINK is true | ||
#endif | ||
|
||
namespace web { | ||
|
||
class IOSContentClient : public content::ContentClient { | ||
public: | ||
IOSContentClient(); | ||
IOSContentClient(const IOSContentClient&) = delete; | ||
IOSContentClient& operator=(const IOSContentClient&) = delete; | ||
~IOSContentClient() override; | ||
|
||
// ContentClient implementation: | ||
blink::OriginTrialPolicy* GetOriginTrialPolicy() override; | ||
std::u16string GetLocalizedString(int message_id) override; | ||
std::u16string GetLocalizedString(int message_id, | ||
const std::u16string& replacement) override; | ||
base::StringPiece GetDataResource( | ||
int resource_id, | ||
ui::ResourceScaleFactor scale_factor) override; | ||
base::RefCountedMemory* GetDataResourceBytes(int resource_id) override; | ||
std::string GetDataResourceString(int resource_id) override; | ||
gfx::Image& GetNativeImageNamed(int resource_id) override; | ||
|
||
private: | ||
embedder_support::OriginTrialPolicyImpl origin_trial_policy_; | ||
}; | ||
|
||
} // namespace web | ||
|
||
#endif // IOS_WEB_CONTENT_INIT_IOS_CONTENT_CLIENT_H_ |
Oops, something went wrong.