Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74e4029

Browse files
committed
Set working directory to package's basedir in renderer.
1 parent bc540ef commit 74e4029

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/common/shell_switches.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ const char kNoTimeout[] = "no-timeout";
4343
// Display no toolbar
4444
const char kNoToolbar[] = "no-toolbar";
4545

46+
// Open specified url
47+
const char kUrl[] = "url";
48+
4649
// Show version and quit
4750
const char kVersion[] = "version";
4851

49-
// Open specified url
50-
const char kUrl[] = "url";
52+
// Set current working directory
53+
const char kWorkingDirectory[] = "working-directory";
5154

5255
const char kmMain[] = "main";
5356
const char kmName[] = "name";

src/common/shell_switches.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ extern const char kDeveloper[];
1616
extern const char kDumpRenderTree[];
1717
extern const char kNoTimeout[];
1818
extern const char kNoToolbar[];
19-
extern const char kVersion[];
2019
extern const char kUrl[];
20+
extern const char kVersion[];
21+
extern const char kWorkingDirectory[];
2122

2223
// Manifest settings
2324
extern const char kmMain[];

src/renderer/shell_content_renderer_client.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "content/nw/src/renderer/shell_content_renderer_client.h"
2222

2323
#include "base/command_line.h"
24+
#include "base/file_path.h"
25+
#include "base/file_util.h"
2426
#include "base/logging.h"
2527
#include "base/utf_string_conversions.h"
2628
#include "content/nw/src/api/dispatcher.h"
@@ -45,6 +47,13 @@ ShellContentRendererClient::~ShellContentRendererClient() {
4547
}
4648

4749
void ShellContentRendererClient::RenderThreadStarted() {
50+
// Change working directory
51+
CommandLine* command_line = CommandLine::ForCurrentProcess();
52+
if (command_line->HasSwitch(switches::kWorkingDirectory)) {
53+
file_util::SetCurrentDirectory(
54+
command_line->GetSwitchValuePath(switches::kWorkingDirectory));
55+
}
56+
4857
// Initialize node after render thread is started
4958
v8::V8::Initialize();
5059
v8::HandleScope scope;

src/shell_content_browser_client.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "base/command_line.h"
2424
#include "base/file_path.h"
25+
#include "base/file_util.h"
2526
#include "content/public/common/content_switches.h"
2627
#include "content/public/browser/browser_url_handler.h"
2728
#include "content/public/browser/resource_dispatcher_host.h"
@@ -69,8 +70,15 @@ void ShellContentBrowserClient::AppendExtraCommandLineSwitches(
6970
command_line->AppendSwitch(switches::kAllowFileAccessFromFiles);
7071
command_line->AppendSwitch(switches::kDisableWebSecurity);
7172

72-
if (nw::GetManifest() && nw::GetUseNode())
73+
if (nw::GetManifest() && nw::GetUseNode()) {
74+
// Whether to disable node
7375
command_line->AppendSwitch(switches::kmNodejs);
76+
77+
// Set cwd
78+
FilePath cwd;
79+
file_util::GetCurrentDirectory(&cwd);
80+
command_line->AppendSwitchPath(switches::kWorkingDirectory, cwd);
81+
}
7482
}
7583

7684
std::string ShellContentBrowserClient::GetApplicationLocale() {

0 commit comments

Comments
 (0)