Skip to content

Commit a3dcabe

Browse files
committed
fix relative require module path for app://
1 parent 6481b8d commit a3dcabe

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/renderer/shell_content_renderer_client.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,20 @@ void ShellContentRendererClient::InstallNodeSymbols(
279279
}
280280

281281
if (use_node) {
282-
v8::Local<v8::Script> script = v8::Script::New(v8::String::New(
282+
RenderViewImpl* rv = RenderViewImpl::FromWebView(frame->view());
283+
v8::Local<v8::Script> script = v8::Script::New(v8::String::New((
283284
// Make node's relative modules work
284285
"if (!process.mainModule.filename) {"
286+
" var root = '" + rv->renderer_preferences_.nw_app_root_path.AsUTF8Unsafe() + "';"
285287
#if defined(OS_WIN)
286288
"process.mainModule.filename = decodeURIComponent(window.location.pathname.substr(1));"
287289
#else
288290
"process.mainModule.filename = decodeURIComponent(window.location.pathname);"
289291
#endif
292+
"if (window.location.href.indexOf('app://') === 0) {process.mainModule.filename = root + '/' + process.mainModule.filename}"
290293
"process.mainModule.paths = global.require('module')._nodeModulePaths(process.cwd());"
291294
"process.mainModule.loaded = true;"
292-
"}"
295+
"}").c_str()
293296
));
294297
script->Run();
295298
}
@@ -318,7 +321,7 @@ v8::Handle<v8::Value> ShellContentRendererClient::ReportException(
318321
// Do nothing if user is listening to uncaughtException.
319322
v8::Local<v8::Value> listeners_v =
320323
node::process->Get(v8::String::New("listeners"));
321-
v8::Local<v8::Function> listeners =
324+
v8::Local<v8::Function> listeners =
322325
v8::Local<v8::Function>::Cast(listeners_v);
323326

324327
v8::Local<v8::Value> argv[1] = { v8::String::New("uncaughtException") };
@@ -327,7 +330,7 @@ v8::Handle<v8::Value> ShellContentRendererClient::ReportException(
327330

328331
uint32_t length = listener_array->Length();
329332
if (length > 1)
330-
return v8::Undefined();
333+
return v8::Undefined();
331334

332335
// Print stacktrace.
333336
v8::Local<v8::String> stack_symbol = v8::String::New("stack");
@@ -341,13 +344,13 @@ v8::Handle<v8::Value> ShellContentRendererClient::ReportException(
341344

342345
RenderView* render_view = GetCurrentRenderView();
343346
if (!render_view)
344-
return v8::Undefined();
347+
return v8::Undefined();
345348

346349
render_view->Send(new ShellViewHostMsg_UncaughtException(
347350
render_view->GetRoutingID(),
348351
error));
349352

350-
return v8::Undefined();
353+
return v8::Undefined();
351354
}
352355

353356
void ShellContentRendererClient::UninstallNodeSymbols(

src/shell_content_browser_client.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ WebContentsViewPort* ShellContentBrowserClient::OverrideCreateWebContentsView(
9292
}
9393
if (package->root()->GetString(switches::kmRemotePages, &rules))
9494
prefs->nw_remote_page_rules = rules;
95+
96+
prefs->nw_app_root_path = package->path();
9597
return NULL;
9698
}
9799

0 commit comments

Comments
 (0)