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

Skip to content

Commit c4c753f

Browse files
committed
Still use multi-process architecture.
1 parent 24dfcbc commit c4c753f

7 files changed

Lines changed: 48 additions & 11 deletions

src/nw_package.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
namespace {
3939

40+
FilePath package_root;
41+
4042
// Don't bother with lifetime since it's used through out the program
4143
base::DictionaryValue* g_manifest = NULL;
4244

@@ -160,7 +162,7 @@ bool InitPackage() {
160162
}
161163

162164
// Set the directory of app as our working directory
163-
file_util::SetCurrentDirectory(path);
165+
package_root = path;
164166

165167
#if defined(OS_WIN)
166168
FilePath manifest_path = path.Append(L"package.json");
@@ -245,6 +247,10 @@ bool GetUseNode() {
245247
return use_node;
246248
}
247249

250+
FilePath GetPackageRoot() {
251+
return package_root;
252+
}
253+
248254
void InitPackageForceNoEmpty() {
249255
base::ThreadRestrictions::SetIOAllowed(true);
250256

src/nw_package.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include "googleurl/src/gurl.h"
2525

26+
class FilePath;
27+
2628
namespace base {
2729
class DictionaryValue;
2830
}
@@ -38,6 +40,9 @@ GURL GetStartupURL();
3840
// Return if we enable node.js
3941
bool GetUseNode();
4042

43+
// Return root path of package
44+
FilePath GetPackageRoot();
45+
4146
// Extract app package and initialize manifest file
4247
void InitPackageForceNoEmpty();
4348

src/renderer/shell_content_renderer_client.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ ShellContentRendererClient::~ShellContentRendererClient() {
4848
}
4949

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

src/shell_browser_main_parts.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ void ShellBrowserMainParts::PostMainMessageLoopRun() {
9595
}
9696

9797
void ShellBrowserMainParts::Init() {
98-
CommandLine& command_line = *CommandLine::ForCurrentProcess();
9998
nw::InitPackageForceNoEmpty();
100-
if (nw::GetUseNode())
101-
command_line.AppendSwitch(switches::kmNodejs);
10299

103100
browser_context_.reset(new ShellBrowserContext(false));
104101
off_the_record_browser_context_.reset(new ShellBrowserContext(true));
@@ -109,6 +106,7 @@ void ShellBrowserMainParts::Init() {
109106
int port = 0;
110107
// See if the user specified a port on the command line (useful for
111108
// automation). If not, use an ephemeral port by specifying 0.
109+
CommandLine& command_line = *CommandLine::ForCurrentProcess();
112110
if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
113111
int temp_port;
114112
std::string port_str =

src/shell_content_browser_client.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,25 @@
2020

2121
#include "content/nw/src/shell_content_browser_client.h"
2222

23+
#include "base/command_line.h"
2324
#include "base/file_path.h"
2425
#include "base/file_util.h"
2526
#include "base/threading/thread_restrictions.h"
2627
#include "content/public/browser/browser_url_handler.h"
2728
#include "content/public/browser/render_process_host.h"
2829
#include "content/public/browser/resource_dispatcher_host.h"
30+
#include "content/nw/src/common/shell_switches.h"
2931
#include "content/nw/src/browser/shell_devtools_delegate.h"
3032
#include "content/nw/src/browser/shell_resource_dispatcher_host_delegate.h"
3133
#include "content/nw/src/media/media_internals.h"
34+
#include "content/nw/src/nw_package.h"
3235
#include "content/nw/src/shell.h"
3336
#include "content/nw/src/shell_browser_context.h"
3437
#include "content/nw/src/shell_browser_main_parts.h"
3538
#include "geolocation/shell_access_token_store.h"
3639
#include "googleurl/src/gurl.h"
3740
#include "webkit/glue/webpreferences.h"
41+
#include "ui/base/l10n/l10n_util.h"
3842

3943
namespace content {
4044

@@ -57,6 +61,23 @@ void ShellContentBrowserClient::RenderProcessHostCreated(
5761
render_process_id_ = host->GetID();
5862
}
5963

64+
std::string ShellContentBrowserClient::GetApplicationLocale() {
65+
return l10n_util::GetApplicationLocale("en-US");
66+
}
67+
68+
void ShellContentBrowserClient::AppendExtraCommandLineSwitches(
69+
CommandLine* command_line,
70+
int child_process_id) {
71+
if (nw::GetManifest() && nw::GetUseNode()) {
72+
// Allow node.js
73+
command_line->AppendSwitch(switches::kmNodejs);
74+
75+
// Set cwd
76+
command_line->AppendSwitchPath(switches::kWorkingDirectory,
77+
nw::GetPackageRoot());
78+
}
79+
}
80+
6081
void ShellContentBrowserClient::ResourceDispatcherHostCreated() {
6182
resource_dispatcher_host_delegate_.reset(
6283
new ShellResourceDispatcherHostDelegate());

src/shell_content_browser_client.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class ShellContentBrowserClient : public ContentBrowserClient {
2727
virtual BrowserMainParts* CreateBrowserMainParts(
2828
const MainFunctionParams& parameters) OVERRIDE;
2929
virtual void RenderProcessHostCreated(RenderProcessHost* host) OVERRIDE;
30+
virtual std::string GetApplicationLocale() OVERRIDE;
31+
virtual void AppendExtraCommandLineSwitches(CommandLine* command_line,
32+
int child_process_id) OVERRIDE;
3033
virtual void ResourceDispatcherHostCreated() OVERRIDE;
3134
virtual AccessTokenStore* CreateAccessTokenStore() OVERRIDE;
3235
virtual void OverrideWebkitPrefs(

src/shell_main_delegate.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "base/path_service.h"
2727
#include "base/utf_string_conversions.h"
2828
#include "content/public/browser/browser_main_runner.h"
29+
#include "content/public/browser/render_process_host.h"
2930
#include "content/public/common/content_switches.h"
3031
#include "content/public/common/url_constants.h"
3132
#include "content/nw/src/common/shell_switches.h"
@@ -99,13 +100,6 @@ bool ShellMainDelegate::BasicStartupComplete(int* exit_code) {
99100
logging::LogEventProvider::Initialize(kContentShellProviderName);
100101
#endif
101102

102-
// Enforce single process
103-
// command_line->AppendSwitch(switches::kSingleProcess);
104-
105-
// Fix navigator.language in single process mode
106-
std::string locale = l10n_util::GetApplicationLocale("en-US");
107-
CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kLang, locale);
108-
109103
InitLogging();
110104

111105
SetContentClient(&content_client_);
@@ -118,6 +112,9 @@ void ShellMainDelegate::PreSandboxStartup() {
118112
OverrideChildProcessPath();
119113
#endif // OS_MACOSX
120114
InitializeResourceBundle();
115+
116+
// Just prevent sandbox
117+
CommandLine::ForCurrentProcess()->AppendSwitch(switches::kNoSandbox);
121118
}
122119

123120
int ShellMainDelegate::RunProcess(

0 commit comments

Comments
 (0)