Skip to content

Commit 5d7ca20

Browse files
committed
set window.__nwWindowId in Window.open()
Fix nwjs#1519
1 parent 38e33ff commit 5d7ca20

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

src/api/dispatcher.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,14 @@ void Dispatcher::OnEvent(int object_id,
102102
}
103103

104104
v8::Handle<v8::Object> Dispatcher::GetObjectRegistry() {
105+
// need to enter node context to access the registry in
106+
// some cases, e.g. normal frame in #1519
107+
node::g_context->Enter();
105108
v8::Handle<v8::Value> registry =
106109
node::g_context->Global()->Get(v8_str("__nwObjectsRegistry"));
107-
// if (registry->IsNull() || registry->IsUndefined())
108-
// return v8::Undefined();
110+
node::g_context->Exit();
111+
if (registry->IsNull() || registry->IsUndefined())
112+
return v8::Undefined();
109113
return registry->ToObject();
110114
}
111115

src/api/dispatcher_bindings.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ DispatcherBindings::CreateShell(const v8::FunctionCallbackInfo<v8::Value>& args)
242242
RenderView* render_view = GetCurrentRenderView();
243243
if (!render_view) {
244244
args.GetReturnValue().Set(v8::ThrowException(v8::Exception::Error(v8::String::New(
245-
"Unable to get render view in CallStaticMethod"))));
245+
"Unable to get render view in CreateShell"))));
246246
return;
247247
}
248248

src/api/window/window.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ exports.Window = {
6262
// Create new shell and get it's routing id.
6363
var id = nw.allocateId();
6464
options.object_id = id;
65+
options.nw_win_id = id;
6566
var routing_id = nw.createShell(url, options);
6667

6768
return new global.Window(routing_id, true, id);

src/nw_shell.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ Shell* Shell::Create(WebContents* source_contents,
114114
params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE;
115115
params.frame_name = std::string();
116116

117+
int nw_win_id = 0;
118+
manifest->GetInteger("nw_win_id", &nw_win_id);
119+
params.nw_win_id = nw_win_id;
120+
117121
new_contents->GetController().LoadURLWithParams(params);
118122
}
119123
// Use the user agent value from the source WebContents.

0 commit comments

Comments
 (0)