Skip to content

Commit

Permalink
MacPWAs: Pass enabled and disabled features to browser
Browse files Browse the repository at this point in the history
Bug: 1162496
Change-Id: Ie8d986ae88b4f909380b527855eb3c84b3a0a71c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2634016
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: Daniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844884}
  • Loading branch information
ccameron-chromium authored and Chromium LUCI CQ committed Jan 19, 2021
1 parent 1383ac8 commit 7b7176b
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions chrome/app_shim/app_shim_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <utility>

#include "base/base_switches.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
Expand Down Expand Up @@ -122,14 +123,14 @@ - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
void AppShimController::FindOrLaunchChrome() {
DCHECK(!chrome_to_connect_to_);
DCHECK(!chrome_launched_by_app_);
const base::CommandLine* app_command_line =
base::CommandLine::ForCurrentProcess();

// If this shim was launched by Chrome, only connect to that that specific
// process.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
app_mode::kLaunchedByChromeProcessId)) {
std::string chrome_pid_string =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
app_mode::kLaunchedByChromeProcessId);
if (app_command_line->HasSwitch(app_mode::kLaunchedByChromeProcessId)) {
std::string chrome_pid_string = app_command_line->GetSwitchValueASCII(
app_mode::kLaunchedByChromeProcessId);
int chrome_pid;
if (!base::StringToInt(chrome_pid_string, &chrome_pid))
LOG(FATAL) << "Invalid PID: " << chrome_pid_string;
Expand All @@ -151,21 +152,31 @@ - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
return;

// In tests, launching Chrome does nothing.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
app_mode::kLaunchedForTest)) {
if (app_command_line->HasSwitch(app_mode::kLaunchedForTest)) {
return;
}

// Otherwise, launch Chrome.
base::FilePath chrome_bundle_path = base::mac::OuterBundlePath();
LOG(INFO) << "Launching " << chrome_bundle_path.value();
base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
command_line.AppendSwitch(switches::kSilentLaunch);
command_line.AppendSwitchPath(switches::kUserDataDir, params_.user_data_dir);
chrome_launched_by_app_.reset(
base::mac::OpenApplicationWithPath(chrome_bundle_path, command_line,
NSWorkspaceLaunchNewInstance),
base::scoped_policy::RETAIN);
base::CommandLine browser_command_line(base::CommandLine::NO_PROGRAM);
browser_command_line.AppendSwitch(switches::kSilentLaunch);
browser_command_line.AppendSwitchPath(switches::kUserDataDir,
params_.user_data_dir);
if (app_command_line->HasSwitch(switches::kEnableFeatures)) {
browser_command_line.AppendSwitchASCII(
switches::kEnableFeatures,
app_command_line->GetSwitchValueASCII(switches::kEnableFeatures));
}
if (app_command_line->HasSwitch(switches::kDisableFeatures)) {
browser_command_line.AppendSwitchASCII(
switches::kDisableFeatures,
app_command_line->GetSwitchValueASCII(switches::kDisableFeatures));
}
chrome_launched_by_app_.reset(base::mac::OpenApplicationWithPath(
chrome_bundle_path, browser_command_line,
NSWorkspaceLaunchNewInstance),
base::scoped_policy::RETAIN);
if (!chrome_launched_by_app_)
LOG(FATAL) << "Failed to launch Chrome.";
}
Expand Down

0 comments on commit 7b7176b

Please sign in to comment.