Skip to content

Commit

Permalink
Add --url command-line switch to set an initial URL. (youtube#4908)
Browse files Browse the repository at this point in the history
b/362296377
  • Loading branch information
aee-google authored Feb 15, 2025
1 parent dc0f4c3 commit afdc78d
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
1 change: 1 addition & 0 deletions cobalt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if (!is_android) {

deps = [
"//cobalt/browser",
"//cobalt/browser:switches",
"//cobalt/renderer:renderer",
"//content/public/app",
"//content/shell:content_shell_app",
Expand Down
9 changes: 9 additions & 0 deletions cobalt/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ source_set("browser") {
}
}

source_set("switches") {
sources = [
"switches.cc",
"switches.h",
]

deps = [ "//base" ]
}

config("embed_polyfilled_javascript_config") {
include_dirs = [ root_gen_dir ]
}
Expand Down
34 changes: 34 additions & 0 deletions cobalt/browser/switches.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2025 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/browser/switches.h"

namespace cobalt {
namespace switches {

namespace {

constexpr char kDefaultURL[] = "https://www.youtube.com/tv";

} // namespace

std::string GetInitialURL(const base::CommandLine& command_line) {
if (command_line.HasSwitch(kInitialURL)) {
return command_line.GetSwitchValueASCII(kInitialURL);
}
return kDefaultURL;
}

} // namespace switches
} // namespace cobalt
33 changes: 33 additions & 0 deletions cobalt/browser/switches.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2025 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 <string>

#include "base/command_line.h"

#ifndef COBALT_BROWSER_SWITCHES_H_
#define COBALT_BROWSER_SWITCHES_H_

namespace cobalt {
namespace switches {

// Allow the user to override the default URL via a command line parameter.
std::string GetInitialURL(const base::CommandLine& command_line);

constexpr char kInitialURL[] = "url";

} // namespace switches
} // namespace cobalt

#endif // COBALT_BROWSER_SWITCHES_H_
9 changes: 7 additions & 2 deletions cobalt/cobalt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
#include <vector>

#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "build/build_config.h"
#include "cobalt/browser/switches.h"
#include "cobalt/cobalt_main_delegate.h"
#include "cobalt/platform_event_source_starboard.h"
#include "content/public/app/content_main.h"
Expand All @@ -46,11 +48,14 @@ static PlatformEventSourceStarboard* g_platform_event_source = nullptr;
} // namespace

int InitCobalt(int argc, const char** argv, const char* initial_deep_link) {
const std::string initial_url =
cobalt::switches::GetInitialURL(base::CommandLine(argc, argv));

// content::ContentMainParams params(g_content_main_delegate.Get().get());
content::ContentMainParams params(g_content_main_delegate);

// TODO: (cobalt b/375241103) Reimplement this in a clean way.
constexpr auto cobalt_args = std::to_array<const char*>(
const auto cobalt_args = std::to_array<const char*>(
{// Disable first run experience, kiosk, etc.
"--disable-fre", "--no-first-run", "--kiosk",
// Enable Blink to work in overlay video mode
Expand All @@ -72,7 +77,7 @@ int InitCobalt(int argc, const char** argv, const char* initial_deep_link) {
// This flag is added specifically for m114 and should be removed after
// rebasing to m120+
"--user-level-memory-pressure-signal-params", "--no-sandbox",
"https://www.youtube.com/tv"});
initial_url.c_str()});
std::vector<const char*> args(argv, argv + argc);
args.insert(args.end(), cobalt_args.begin(), cobalt_args.end());

Expand Down

0 comments on commit afdc78d

Please sign in to comment.