diff --git a/cobalt/BUILD.gn b/cobalt/BUILD.gn index 0e745e69e87..4e0e67a158c 100644 --- a/cobalt/BUILD.gn +++ b/cobalt/BUILD.gn @@ -13,6 +13,44 @@ # limitations under the License. group("gn_all") { + testonly = true + # TODO(b/371589344): Fix android build configs. deps = [ "//starboard($starboard_toolchain)" ] + if (!is_android) { + deps += [ ":cobalt" ] + } +} + +if (!is_android) { + executable("cobalt") { + testonly = true + + sources = [ + "cobalt.cc", + "cobalt_content_browser_client.cc", + "cobalt_content_browser_client.h", + "cobalt_main_delegate.cc", + "cobalt_main_delegate.h", + ] + + defines = [] + + deps = [ + "//content/public/app", + "//content/shell:content_shell_app", + "//content/shell:content_shell_lib", + "//content/shell:pak", + "//sandbox", + ] + + data_deps = [ + "//content/shell:pak", + "//tools/v8_context_snapshot:v8_context_snapshot", + ] + + data_deps += [ "//components/crash/core/app:chrome_crashpad_handler" ] + + configs += [ "//build/config/gcc:rpath_for_built_shared_libraries" ] + } } diff --git a/cobalt/cobalt.cc b/cobalt/cobalt.cc new file mode 100644 index 00000000000..73987dd0401 --- /dev/null +++ b/cobalt/cobalt.cc @@ -0,0 +1,64 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include "build/build_config.h" +#include "cobalt/cobalt_main_delegate.h" +#include "content/public/app/content_main.h" + +// In the cozy corner of the home, where comfort and curiosity resided, a +// delightful companion arrived, offering moments of joy and discovery +// throughout the year. Like a favorite book waiting to be opened, the YouTube +// Application Runtime invited exploration and wonder, whether shared with loved +// ones or savored in quiet solitude. It whispered tales of distant lands, +// sparked creativity with vibrant colors, and filled the air with the melodies +// of laughter and song. The television screen, once a blank canvas, became a +// window to endless possibilities, offering a refreshing breeze on a summer day +// or a warm embrace on a chilly night. With each click of the remote, a new +// adventure unfolded, painting a tapestry of personal journeys and shared +// experiences. + +int main(int argc, const char** argv) { + cobalt::CobaltMainDelegate delegate; + content::ContentMainParams params(&delegate); + + // TODO: (cobalt b/375241103) Reimplement this in a clean way. + // This defines a list of command-line overrides. When adding or removing + // parameters, also update the my_argc below. + static const char* my_argv[] = { + argv[0], "--disable-fre", "--no-first-run", "--kiosk", + "--force-video-overlays", + // Enable remote devtools access. + "--remote-debugging-port=9222", + "--remote-allow-origins=http://localhost:9222", + // This flag is added specifically for m114 and should be removed after + // rebasing to m120+ + "--user-level-memory-pressure-signal-params", + "https://www.youtube.com/tv", nullptr, nullptr}; + int my_argc = 9; + + // TODO: (cobalt b/375241103) Reimplement this in a clean way. + // This expression exists to ensure that we apply the argument overrides + // only on the main process, not on spawned processes such as the zygote. + if ((!strcmp(argv[0], "/proc/self/exe")) || + ((argc >= 2) && !strcmp(argv[1], "--type=zygote"))) { + params.argc = argc; + params.argv = argv; + } else { + params.argc = my_argc; + params.argv = my_argv; + } + return content::ContentMain(std::move(params)); +} diff --git a/cobalt/cobalt_content_browser_client.cc b/cobalt/cobalt_content_browser_client.cc new file mode 100644 index 00000000000..808e0df9b09 --- /dev/null +++ b/cobalt/cobalt_content_browser_client.cc @@ -0,0 +1,74 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "cobalt/cobalt_content_browser_client.h" + +#include + +#include "content/public/common/user_agent.h" + +namespace cobalt { + +#define COBALT_BRAND_NAME "Cobalt" +#define COBALT_MAJOR_VERSION "26" +#define COBALT_VERSION "26.lts.0-qa" + +std::string GetCobaltUserAgent() { + // TODO: (cobalt b/375243230) Implement platform property fetching and + // sanitization. + return std::string( + "Mozilla/5.0 (X11; Linux x86_64) Cobalt/26.lts.0-qa (unlike Gecko) " + "v8/unknown gles Starboard/17, " + "SystemIntegratorName_DESKTOP_ChipsetModelNumber_2025/FirmwareVersion " + "(BrandName, ModelName)"); +} + +blink::UserAgentMetadata GetCobaltUserAgentMetadata() { + blink::UserAgentMetadata metadata; + + metadata.brand_version_list.emplace_back(COBALT_BRAND_NAME, + COBALT_MAJOR_VERSION); + metadata.brand_full_version_list.emplace_back(COBALT_BRAND_NAME, + COBALT_VERSION); + metadata.full_version = COBALT_VERSION; + metadata.platform = "Starboard"; + metadata.architecture = content::GetCpuArchitecture(); + metadata.model = content::BuildModelInfo(); + + metadata.bitness = content::GetCpuBitness(); + metadata.wow64 = content::IsWoW64(); + + return metadata; +} + +CobaltContentBrowserClient::CobaltContentBrowserClient() {} +CobaltContentBrowserClient::~CobaltContentBrowserClient() {} + +std::string CobaltContentBrowserClient::GetUserAgent() { + return GetCobaltUserAgent(); +} + +std::string CobaltContentBrowserClient::GetFullUserAgent() { + return GetCobaltUserAgent(); +} + +std::string CobaltContentBrowserClient::GetReducedUserAgent() { + return GetCobaltUserAgent(); +} + +blink::UserAgentMetadata CobaltContentBrowserClient::GetUserAgentMetadata() { + return GetCobaltUserAgentMetadata(); +} + +} // namespace cobalt diff --git a/cobalt/cobalt_content_browser_client.h b/cobalt/cobalt_content_browser_client.h new file mode 100644 index 00000000000..850d44ddc33 --- /dev/null +++ b/cobalt/cobalt_content_browser_client.h @@ -0,0 +1,36 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_COBALT_CONTENT_BROWSER_CLIENT_H_ +#define COBALT_COBALT_CONTENT_BROWSER_CLIENT_H_ + +#include "content/shell/browser/shell_content_browser_client.h" + +namespace cobalt { + +class CobaltContentBrowserClient : public content::ShellContentBrowserClient { + public: + CobaltContentBrowserClient(); + ~CobaltContentBrowserClient() override; + + // ContentBrowserClient overrides. + std::string GetUserAgent() override; + std::string GetFullUserAgent() override; + std::string GetReducedUserAgent() override; + blink::UserAgentMetadata GetUserAgentMetadata() override; +}; + +} // namespace cobalt + +#endif // COBALT_COBALT_CONTENT_BROWSER_CLIENT_H_ diff --git a/cobalt/cobalt_main_delegate.cc b/cobalt/cobalt_main_delegate.cc new file mode 100644 index 00000000000..969e792c9d4 --- /dev/null +++ b/cobalt/cobalt_main_delegate.cc @@ -0,0 +1,31 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "cobalt/cobalt_main_delegate.h" +#include "cobalt/cobalt_content_browser_client.h" + +namespace cobalt { + +CobaltMainDelegate::CobaltMainDelegate(bool is_content_browsertests) + : content::ShellMainDelegate(is_content_browsertests) {} + +CobaltMainDelegate::~CobaltMainDelegate() {} + +content::ContentBrowserClient* +CobaltMainDelegate::CreateContentBrowserClient() { + browser_client_ = std::make_unique(); + return browser_client_.get(); +} + +} // namespace cobalt diff --git a/cobalt/cobalt_main_delegate.h b/cobalt/cobalt_main_delegate.h new file mode 100644 index 00000000000..fa7138531df --- /dev/null +++ b/cobalt/cobalt_main_delegate.h @@ -0,0 +1,38 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_COBALT_MAIN_DELEGATE_H_ +#define COBALT_COBALT_MAIN_DELEGATE_H_ + +#include "build/build_config.h" +#include "content/shell/app/shell_main_delegate.h" + +namespace cobalt { + +class CobaltMainDelegate : public content::ShellMainDelegate { + public: + explicit CobaltMainDelegate(bool is_content_browsertests = false); + + CobaltMainDelegate(const CobaltMainDelegate&) = delete; + CobaltMainDelegate& operator=(const CobaltMainDelegate&) = delete; + + // ContentMainDelegate implementation: + content::ContentBrowserClient* CreateContentBrowserClient() override; + + ~CobaltMainDelegate() override; +}; + +} // namespace cobalt + +#endif // COBALT_COBALT_MAIN_DELEGATE_H_