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

Skip to content

Commit 2c1784c

Browse files
committed
Use single process mode for node-webkit.
1 parent 76baaec commit 2c1784c

6 files changed

Lines changed: 15 additions & 42 deletions

src/renderer/shell_content_renderer_client.cc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "base/utf_string_conversions.h"
2828
#include "content/nw/src/api/dispatcher.h"
2929
#include "content/nw/src/common/shell_switches.h"
30+
#include "content/nw/src/nw_package.h"
3031
#include "content/nw/src/nw_version.h"
3132
#include "content/nw/src/renderer/prerenderer/prerenderer_client.h"
3233
#include "content/nw/src/renderer/shell_render_process_observer.h"
@@ -47,13 +48,6 @@ ShellContentRendererClient::~ShellContentRendererClient() {
4748
}
4849

4950
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-
5751
// Initialize node after render thread is started
5852
v8::V8::Initialize();
5953
v8::HandleScope scope;
@@ -104,7 +98,8 @@ bool ShellContentRendererClient::WillSetSecurityToken(
10498
void ShellContentRendererClient::InstallNodeSymbols(
10599
v8::Handle<v8::Context> context) {
106100
// Do we integrate node?
107-
bool use_node = CommandLine::ForCurrentProcess()->HasSwitch(switches::kmNodejs);
101+
bool use_node =
102+
CommandLine::ForCurrentProcess()->HasSwitch(switches::kmNodejs);
108103

109104
// Test if protocol is file:
110105
v8::Local<v8::Script> protocol_script = v8::Script::New(v8::String::New(

src/shell_browser_main.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
#include "base/logging.h"
2626
#include "base/memory/scoped_ptr.h"
2727
#include "base/threading/thread_restrictions.h"
28+
#include "content/public/common/content_switches.h"
29+
#include "content/public/browser/browser_main_runner.h"
2830
#include "content/nw/src/common/shell_switches.h"
29-
#include "content/nw/src/nw_package.h"
3031
#include "content/nw/src/shell.h"
3132
#include "content/nw/src/shell_browser_context.h"
3233
#include "content/nw/src/shell_content_browser_client.h"
33-
#include "content/public/browser/browser_main_runner.h"
3434

3535
// Main routine for running as the Browser process.
3636
int ShellBrowserMain(const content::MainFunctionParams& parameters) {

src/shell_browser_main_parts.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ void ShellBrowserMainParts::PostMainMessageLoopRun() {
116116
}
117117

118118
void ShellBrowserMainParts::Init() {
119+
CommandLine& command_line = *CommandLine::ForCurrentProcess();
119120
nw::InitPackageForceNoEmpty();
121+
if (nw::GetUseNode())
122+
command_line.AppendSwitch(switches::kmNodejs);
120123

121124
browser_context_.reset(new ShellBrowserContext(false));
122125
off_the_record_browser_context_.reset(new ShellBrowserContext(true));
@@ -129,7 +132,6 @@ void ShellBrowserMainParts::Init() {
129132
#if !defined(OS_ANDROID)
130133
// See if the user specified a port on the command line (useful for
131134
// automation). If not, use an ephemeral port by specifying 0.
132-
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
133135
if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
134136
int temp_port;
135137
std::string port_str =

src/shell_content_browser_client.cc

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "content/nw/src/shell.h"
3535
#include "content/nw/src/shell_browser_context.h"
3636
#include "content/nw/src/shell_browser_main_parts.h"
37-
#include "content/nw/src/nw_package.h"
3837
#include "geolocation/shell_access_token_store.h"
3938
#include "googleurl/src/gurl.h"
4039
#include "ui/base/l10n/l10n_util.h"
@@ -65,25 +64,6 @@ void ShellContentBrowserClient::RenderViewHostCreated(
6564
RenderViewHost* render_view_host) {
6665
}
6766

68-
void ShellContentBrowserClient::AppendExtraCommandLineSwitches(
69-
CommandLine* command_line, int child_process_id) {
70-
// Disable web security
71-
command_line->AppendSwitch(switches::kAllowFileAccessFromFiles);
72-
command_line->AppendSwitch(switches::kDisableWebSecurity);
73-
74-
if (nw::GetManifest() && nw::GetUseNode()) {
75-
base::ThreadRestrictions::SetIOAllowed(true);
76-
77-
// Whether to disable node
78-
command_line->AppendSwitch(switches::kmNodejs);
79-
80-
// Set cwd
81-
FilePath cwd;
82-
file_util::GetCurrentDirectory(&cwd);
83-
command_line->AppendSwitchPath(switches::kWorkingDirectory, cwd);
84-
}
85-
}
86-
8767
std::string ShellContentBrowserClient::GetApplicationLocale() {
8868
return l10n_util::GetApplicationLocale("en-US");
8969
}

src/shell_content_browser_client.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ class ShellContentBrowserClient : public ContentBrowserClient {
2727
const MainFunctionParams& parameters) OVERRIDE;
2828
virtual void RenderViewHostCreated(
2929
RenderViewHost* render_view_host) OVERRIDE;
30-
virtual void AppendExtraCommandLineSwitches(CommandLine* command_line,
31-
int child_process_id) OVERRIDE;
3230
virtual std::string GetApplicationLocale() OVERRIDE;
3331
virtual void ResourceDispatcherHostCreated() OVERRIDE;
3432
virtual AccessTokenStore* CreateAccessTokenStore() OVERRIDE;

src/shell_main_delegate.cc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,13 @@ bool ShellMainDelegate::BasicStartupComplete(int* exit_code) {
105105
logging::LogEventProvider::Initialize(kContentShellProviderName);
106106
#endif
107107

108-
// Print version and quit
109-
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kVersion)) {
110-
printf("nw %s\nnode %s\n", NW_VERSION, NODE_VERSION);
111-
*exit_code = 0;
112-
return true;
113-
}
108+
// Disable web security
109+
CommandLine* command_line = CommandLine::ForCurrentProcess();
110+
command_line->AppendSwitch(switches::kAllowFileAccessFromFiles);
111+
command_line->AppendSwitch(switches::kDisableWebSecurity);
112+
113+
// Enforce single process
114+
command_line->AppendSwitch(switches::kSingleProcess);
114115

115116
InitLogging();
116117

@@ -124,9 +125,6 @@ void ShellMainDelegate::PreSandboxStartup() {
124125
OverrideChildProcessPath();
125126
#endif // OS_MACOSX
126127
InitializeResourceBundle();
127-
128-
// Just prevent sandbox
129-
CommandLine::ForCurrentProcess()->AppendSwitch(switches::kNoSandbox);
130128
}
131129

132130
int ShellMainDelegate::RunProcess(

0 commit comments

Comments
 (0)