Skip to content

Commit

Permalink
Poor man's cobalt target
Browse files Browse the repository at this point in the history
  • Loading branch information
jellefoks committed Oct 17, 2024
1 parent aaacbee commit 8ce2c2e
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 0 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ group("gn_all") {
deps = [
"//base:base_perftests",
"//base:base_unittests",
"//cobalt",
"//codelabs",
"//components:components_unittests",
"//components/gwp_asan:gwp_asan_unittests",
Expand Down
64 changes: 64 additions & 0 deletions cobalt/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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.

import("//build/config/chromecast_build.gni")
import("//build/config/chromeos/ui_mode.gni")
import("//build/config/features.gni")
import("//build/config/ozone.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/config/ui.gni")
import("//build/config/win/console_app.gni")
import("//build/config/win/manifest.gni")
import("//gpu/vulkan/features.gni")
import("//media/media_options.gni")
import("//mojo/public/tools/bindings/mojom.gni")
import("//ppapi/buildflags/buildflags.gni")
import("//tools/grit/grit_rule.gni")
import("//tools/grit/repack.gni")
import("//tools/v8_context_snapshot/v8_context_snapshot.gni")
if (is_android) {
import("//build/config/android/config.gni")
}

if (is_android) {
group("cobalt") {
testonly = true
deps = [ "//content/shell/android:content_shell_apk" ]
}
} else {
executable("cobalt") {
testonly = true

sources = [ "cobalt.cc" ]

defines = []

deps = [
"//content/shell:content_shell_app",
"//content/shell:content_shell_lib",
"//content/shell:pak",
"//content/public/app",
"//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" ]
}
}
71 changes: 71 additions & 0 deletions cobalt/cobalt.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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 <unistd.h>

#include "build/build_config.h"
#include "content/public/app/content_main.h"
#include "content/shell/app/shell_main_delegate.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) {
content::ShellMainDelegate delegate;
content::ContentMainParams params(&delegate);
printf("%u: Passed argc = %d\n", static_cast<unsigned int>(getpid()), argc);
for (int i = 0; i < argc; ++i) {
printf("%u: Passed argv[%d] = %s\n", static_cast<unsigned int>(getpid()), i,
argv[i]);
}

static const char* my_argv[] = {
argv[0],
"--disable-fre",
"--no-first-run",
"--kiosk",
"--force-video-overlays",
"--remote-debugging-port=9222",
"--remote-allow-origins=http://localhost:9222",
"--use-cobalt-user-agent",
"https://www.youtube.com/tv",
nullptr,
nullptr};
int my_argc = 9;

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;
}
printf("%u: Used argc = %d\n", static_cast<unsigned int>(getpid()),
params.argc);
for (int i = 0; i < params.argc; ++i) {
printf("%u: Used argv[%d] = %s\n", static_cast<unsigned int>(getpid()), i,
params.argv[i]);
}
return content::ContentMain(std::move(params));
}
3 changes: 3 additions & 0 deletions content/public/common/content_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,9 @@ const char kVideoImageTextureTarget[] = "video-image-texture-target";
// Set when Chromium should use a mobile user agent.
const char kUseMobileUserAgent[] = "use-mobile-user-agent";

// Set when Chromium should use a mobile user agent.
const char kUseCobaltUserAgent[] = "use-cobalt-user-agent";

// Use the MockCertVerifier. This only works in test code.
const char kUseMockCertVerifierForTesting[] =
"use-mock-cert-verifier-for-testing";
Expand Down
1 change: 1 addition & 0 deletions content/public/common/content_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ CONTENT_EXPORT extern const char kUseFakeUIForFedCM[];
CONTENT_EXPORT extern const char kUseFakeUIForMediaStream[];
CONTENT_EXPORT extern const char kVideoImageTextureTarget[];
CONTENT_EXPORT extern const char kUseMobileUserAgent[];
CONTENT_EXPORT extern const char kUseCobaltUserAgent[];
CONTENT_EXPORT extern const char kUseMockCertVerifierForTesting[];
extern const char kUtilityCmdPrefix[];
CONTENT_EXPORT extern const char kUtilityProcess[];
Expand Down
8 changes: 8 additions & 0 deletions content/shell/browser/shell_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,14 @@ base::FilePath ShellContentBrowserClient::GetFirstPartySetsDirectory() {
}

std::string ShellContentBrowserClient::GetUserAgent() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kUseCobaltUserAgent)) {
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)");
}
return GetShellUserAgent();
}

Expand Down

0 comments on commit 8ce2c2e

Please sign in to comment.