Skip to content

Commit

Permalink
Poor man's cobalt target (#4277)
Browse files Browse the repository at this point in the history
Minimal cobalt target. Works on Linux only (for now).

$ autoninja -C out/chrobalt cobalt
$ out/chrobalt/cobalt

It also enables the devtools listening on 9222.

b/374191454
  • Loading branch information
jellefoks authored Oct 24, 2024
1 parent a828c6e commit e183344
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cobalt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
}
64 changes: 64 additions & 0 deletions cobalt/cobalt.cc
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.

#include <unistd.h>

#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));
}
74 changes: 74 additions & 0 deletions cobalt/cobalt_content_browser_client.cc
Original file line number Diff line number Diff line change
@@ -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 <string>

#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
36 changes: 36 additions & 0 deletions cobalt/cobalt_content_browser_client.h
Original file line number Diff line number Diff line change
@@ -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_
31 changes: 31 additions & 0 deletions cobalt/cobalt_main_delegate.cc
Original file line number Diff line number Diff line change
@@ -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<CobaltContentBrowserClient>();
return browser_client_.get();
}

} // namespace cobalt
38 changes: 38 additions & 0 deletions cobalt/cobalt_main_delegate.h
Original file line number Diff line number Diff line change
@@ -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_

0 comments on commit e183344

Please sign in to comment.