diff --git a/atom/app/atom_main_delegate.cc b/atom/app/atom_main_delegate.cc index 9ce8dc504a92..170bee2be84a 100644 --- a/atom/app/atom_main_delegate.cc +++ b/atom/app/atom_main_delegate.cc @@ -21,10 +21,18 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +#if defined(OS_MACOSX) +#include "chrome/browser/mac/relauncher.h" +#endif + namespace atom { namespace { +#if defined(OS_MACOSX) +const char* kRelauncherProcess = "relauncher"; +#endif + bool IsBrowserProcess(base::CommandLine* cmd) { std::string process_type = cmd->GetSwitchValueASCII(switches::kProcessType); return process_type.empty(); @@ -146,6 +154,26 @@ content::ContentUtilityClient* AtomMainDelegate::CreateContentUtilityClient() { return utility_client_.get(); } +#if defined(OS_MACOSX) +int AtomMainDelegate::RunProcess( + const std::string& process_type, + const content::MainFunctionParams& main_function_params) { + if (process_type == kRelauncherProcess) + return mac_relauncher::internal::RelauncherMain(main_function_params); + else + return -1; +} + +bool AtomMainDelegate::ShouldSendMachPort(const std::string& process_type) { + return process_type != kRelauncherProcess; +} + +bool AtomMainDelegate::DelaySandboxInitialization( + const std::string& process_type) { + return process_type == kRelauncherProcess; +} +#endif + std::unique_ptr AtomMainDelegate::CreateContentClient() { return std::unique_ptr(new AtomContentClient); diff --git a/atom/app/atom_main_delegate.h b/atom/app/atom_main_delegate.h index 2f9474cff563..b12a6dcdc4a8 100644 --- a/atom/app/atom_main_delegate.h +++ b/atom/app/atom_main_delegate.h @@ -5,6 +5,8 @@ #ifndef ATOM_APP_ATOM_MAIN_DELEGATE_H_ #define ATOM_APP_ATOM_MAIN_DELEGATE_H_ +#include + #include "brightray/common/main_delegate.h" #include "brightray/common/content_client.h" @@ -22,6 +24,13 @@ class AtomMainDelegate : public brightray::MainDelegate { content::ContentBrowserClient* CreateContentBrowserClient() override; content::ContentRendererClient* CreateContentRendererClient() override; content::ContentUtilityClient* CreateContentUtilityClient() override; +#if defined(OS_MACOSX) + int RunProcess( + const std::string& process_type, + const content::MainFunctionParams& main_function_params) override; + bool ShouldSendMachPort(const std::string& process_type) override; + bool DelaySandboxInitialization(const std::string& process_type) override; +#endif // brightray::MainDelegate: std::unique_ptr CreateContentClient() override; diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 3599e3195fc5..c5bce573ddfa 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -450,6 +450,7 @@ void App::BuildPrototype( mate::ObjectTemplateBuilder(isolate, prototype) .SetMethod("quit", base::Bind(&Browser::Quit, browser)) .SetMethod("exit", base::Bind(&Browser::Exit, browser)) + .SetMethod("relaunch", base::Bind(&Browser::Relaunch, browser)) .SetMethod("focus", base::Bind(&Browser::Focus, browser)) .SetMethod("getVersion", base::Bind(&Browser::GetVersion, browser)) .SetMethod("setVersion", base::Bind(&Browser::SetVersion, browser)) diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 18d0c97c93ac..2b446d621fd4 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -53,6 +53,10 @@ class Browser : public WindowListObserver { // Cleanup everything and shutdown the application gracefully. void Shutdown(); + // Restart the app. + void Relaunch(const std::vector& args, + const std::string& app); + // Focus the application. void Focus(); diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index 4561eab8c950..9149a2126977 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -13,11 +13,22 @@ #include "base/mac/foundation_util.h" #include "base/strings/sys_string_conversions.h" #include "brightray/common/application_info.h" +#include "brightray/common/mac/main_application_bundle.h" +#include "chrome/browser/mac/relauncher.h" #include "net/base/mac/url_conversions.h" #include "url/gurl.h" namespace atom { +void Browser::Relaunch(const std::vector& args, + const std::string& app) { + std::vector args_with_app(args); + args_with_app.insert( + args_with_app.begin(), + app.empty() ? brightray::MainApplicationBundlePath().value() : app); + mac_relauncher::RelaunchApp(args_with_app); +} + void Browser::Focus() { [[AtomApplication sharedApplication] activateIgnoringOtherApps:YES]; } diff --git a/chromium_src/chrome/browser/mac/relauncher.cc b/chromium_src/chrome/browser/mac/relauncher.cc index 40ea5371bf90..f76e44c637e3 100644 --- a/chromium_src/chrome/browser/mac/relauncher.cc +++ b/chromium_src/chrome/browser/mac/relauncher.cc @@ -29,8 +29,6 @@ #include "base/process/launch.h" #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" -#include "chrome/browser/mac/install_from_dmg.h" -#include "chrome/common/chrome_switches.h" #include "content/public/common/content_paths.h" #include "content/public/common/content_switches.h" #include "content/public/common/main_function_params.h" @@ -66,9 +64,7 @@ const char kPSNArg[] = "-psn_"; // Returns the "type" argument identifying a relauncher process // ("--type=relauncher"). std::string RelauncherTypeArg() { - return base::StringPrintf("--%s=%s", - switches::kProcessType, - switches::kRelauncherProcess); + return base::StringPrintf("--%s=%s", switches::kProcessType, "relauncher"); } } // namespace @@ -292,12 +288,9 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) { // start it in the background. bool background = false; bool in_relaunch_args = false; - std::string dmg_bsd_device_name; bool seen_relaunch_executable = false; std::string relaunch_executable; const std::string relauncher_arg_separator(kRelauncherArgSeparator); - const std::string relauncher_dmg_device_arg = - base::StringPrintf("--%s=", switches::kRelauncherProcessDMGDevice); for (int argv_index = 2; argv_index < argc; ++argv_index) { const std::string arg(argv[argv_index]); @@ -311,11 +304,6 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) { in_relaunch_args = true; } else if (arg == kRelauncherBackgroundArg) { background = true; - } else if (arg.compare(0, - relauncher_dmg_device_arg.size(), - relauncher_dmg_device_arg) == 0) { - dmg_bsd_device_name.assign( - arg.substr(relauncher_dmg_device_arg.size())); } } else { if (!seen_relaunch_executable) { @@ -369,10 +357,6 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) { // relaunching). From this point on, only clean-up tasks should occur, and // failures are tolerable. - if (!dmg_bsd_device_name.empty()) { - EjectAndTrashDiskImage(dmg_bsd_device_name); - } - return 0; }