Pass original argv in callback
This commit is contained in:
parent
d52ef50b01
commit
6bfe06ec4e
6 changed files with 20 additions and 46 deletions
|
@ -19,7 +19,6 @@
|
||||||
#include "atom/browser/api/atom_api_web_contents.h"
|
#include "atom/browser/api/atom_api_web_contents.h"
|
||||||
#include "atom/common/native_mate_converters/callback.h"
|
#include "atom/common/native_mate_converters/callback.h"
|
||||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "atom/common/native_mate_converters/command_line_converter.h"
|
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
#include "atom/common/options_switches.h"
|
#include "atom/common/options_switches.h"
|
||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
|
@ -114,7 +113,7 @@ int GetPathConstant(const std::string& name) {
|
||||||
|
|
||||||
bool NotificationCallbackWrapper(
|
bool NotificationCallbackWrapper(
|
||||||
const ProcessSingleton::NotificationCallback& callback,
|
const ProcessSingleton::NotificationCallback& callback,
|
||||||
const base::CommandLine& cmd,
|
const base::CommandLine::StringVector& cmd,
|
||||||
const base::FilePath& cwd) {
|
const base::FilePath& cwd) {
|
||||||
// Make sure the callback is called after app gets ready.
|
// Make sure the callback is called after app gets ready.
|
||||||
if (Browser::Get()->is_ready()) {
|
if (Browser::Get()->is_ready()) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ void FatalErrorCallback(const char* location, const char* message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log(const base::string16& message) {
|
void Log(const base::string16& message) {
|
||||||
std::cout << message;
|
std::cout << message << std::flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
// Copyright (c) 2014 GitHub, Inc.
|
|
||||||
// Use of this source code is governed by the MIT license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
#ifndef ATOM_COMMON_NATIVE_MATE_CONVERTERS_COMMAND_LINE_CONVERTER_H_
|
|
||||||
#define ATOM_COMMON_NATIVE_MATE_CONVERTERS_COMMAND_LINE_CONVERTER_H_
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
|
||||||
#include "base/command_line.h"
|
|
||||||
|
|
||||||
namespace mate {
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct Converter<base::CommandLine> {
|
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
||||||
const base::CommandLine& val) {
|
|
||||||
return Converter<base::CommandLine::StringType>::ToV8(
|
|
||||||
isolate, val.GetCommandLineString());
|
|
||||||
}
|
|
||||||
static bool FromV8(v8::Isolate* isolate,
|
|
||||||
v8::Local<v8::Value> val,
|
|
||||||
base::CommandLine* out) {
|
|
||||||
base::FilePath::StringType path;
|
|
||||||
|
|
||||||
if (Converter<base::FilePath::StringType>::FromV8(isolate, val, &path)) {
|
|
||||||
*out = base::CommandLine(base::FilePath(path));
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace mate
|
|
||||||
|
|
||||||
#endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_COMMAND_LINE_CONVERTER_H_
|
|
|
@ -60,7 +60,7 @@ class ProcessSingleton : public base::NonThreadSafe {
|
||||||
// handled within the current browser instance or false if the remote process
|
// handled within the current browser instance or false if the remote process
|
||||||
// should handle it (i.e., because the current process is shutting down).
|
// should handle it (i.e., because the current process is shutting down).
|
||||||
using NotificationCallback =
|
using NotificationCallback =
|
||||||
base::Callback<bool(const base::CommandLine& command_line,
|
base::Callback<bool(const base::CommandLine::StringVector& command_line,
|
||||||
const base::FilePath& current_directory)>;
|
const base::FilePath& current_directory)>;
|
||||||
|
|
||||||
ProcessSingleton(const base::FilePath& user_data_dir,
|
ProcessSingleton(const base::FilePath& user_data_dir,
|
||||||
|
|
|
@ -600,7 +600,7 @@ void ProcessSingleton::LinuxWatcher::HandleMessage(
|
||||||
DCHECK(ui_message_loop_ == base::MessageLoop::current());
|
DCHECK(ui_message_loop_ == base::MessageLoop::current());
|
||||||
DCHECK(reader);
|
DCHECK(reader);
|
||||||
|
|
||||||
if (parent_->notification_callback_.Run(base::CommandLine(argv),
|
if (parent_->notification_callback_.Run(argv,
|
||||||
base::FilePath(current_dir))) {
|
base::FilePath(current_dir))) {
|
||||||
// Send back "ACK" message to prevent the client process from starting up.
|
// Send back "ACK" message to prevent the client process from starting up.
|
||||||
reader->FinishWithACK(kACKToken, arraysize(kACKToken) - 1);
|
reader->FinishWithACK(kACKToken, arraysize(kACKToken) - 1);
|
||||||
|
|
|
@ -77,8 +77,21 @@ BOOL CALLBACK BrowserWindowEnumeration(HWND window, LPARAM param) {
|
||||||
return !*result;
|
return !*result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert Command line string to argv.
|
||||||
|
base::CommandLine::StringVector CommandLineStringToArgv(
|
||||||
|
const std::wstring& command_line_string) {
|
||||||
|
int num_args = 0;
|
||||||
|
wchar_t** args = NULL;
|
||||||
|
args = ::CommandLineToArgvW(command_line_string.c_str(), &num_args);
|
||||||
|
base::CommandLine::StringVector argv;
|
||||||
|
for (int i = 0; i < num_args; ++i)
|
||||||
|
argv.push_back(std::wstring(args[i]));
|
||||||
|
LocalFree(args);
|
||||||
|
return argv;
|
||||||
|
}
|
||||||
|
|
||||||
bool ParseCommandLine(const COPYDATASTRUCT* cds,
|
bool ParseCommandLine(const COPYDATASTRUCT* cds,
|
||||||
base::CommandLine* parsed_command_line,
|
base::CommandLine::StringVector* parsed_command_line,
|
||||||
base::FilePath* current_directory) {
|
base::FilePath* current_directory) {
|
||||||
// We should have enough room for the shortest command (min_message_size)
|
// We should have enough room for the shortest command (min_message_size)
|
||||||
// and also be a multiple of wchar_t bytes. The shortest command
|
// and also be a multiple of wchar_t bytes. The shortest command
|
||||||
|
@ -131,7 +144,7 @@ bool ParseCommandLine(const COPYDATASTRUCT* cds,
|
||||||
// Get command line.
|
// Get command line.
|
||||||
const std::wstring cmd_line =
|
const std::wstring cmd_line =
|
||||||
msg.substr(second_null + 1, third_null - second_null);
|
msg.substr(second_null + 1, third_null - second_null);
|
||||||
*parsed_command_line = base::CommandLine::FromString(cmd_line);
|
*parsed_command_line = CommandLineStringToArgv(cmd_line);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -149,7 +162,7 @@ bool ProcessLaunchNotification(
|
||||||
// Handle the WM_COPYDATA message from another process.
|
// Handle the WM_COPYDATA message from another process.
|
||||||
const COPYDATASTRUCT* cds = reinterpret_cast<COPYDATASTRUCT*>(lparam);
|
const COPYDATASTRUCT* cds = reinterpret_cast<COPYDATASTRUCT*>(lparam);
|
||||||
|
|
||||||
base::CommandLine parsed_command_line(base::CommandLine::NO_PROGRAM);
|
base::CommandLine::StringVector parsed_command_line;
|
||||||
base::FilePath current_directory;
|
base::FilePath current_directory;
|
||||||
if (!ParseCommandLine(cds, &parsed_command_line, ¤t_directory)) {
|
if (!ParseCommandLine(cds, &parsed_command_line, ¤t_directory)) {
|
||||||
*result = TRUE;
|
*result = TRUE;
|
||||||
|
|
Loading…
Add table
Reference in a new issue