Skip to content

Commit a4de9e4

Browse files
committed
don't force close remote instance with Node support
Still use the 'close' event; Bind Window object on opening Remote window with normal frame is still force closed Fix nwjs#1778
1 parent fa67cb0 commit a4de9e4

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

src/api/api_messages.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,5 @@ IPC_MESSAGE_CONTROL0(ShellViewMsg_ClearCache)
100100

101101
IPC_SYNC_MESSAGE_ROUTED0_1(ShellViewHostMsg_AllocateId, int)
102102

103+
IPC_SYNC_MESSAGE_ROUTED1_1(ShellViewHostMsg_SetForceClose, bool, int)
104+

src/api/dispatcher_host.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ bool DispatcherHost::OnMessageReceived(const IPC::Message& message) {
115115
IPC_MESSAGE_HANDLER(ShellViewHostMsg_GetShellId, OnGetShellId);
116116
IPC_MESSAGE_HANDLER(ShellViewHostMsg_CreateShell, OnCreateShell);
117117
IPC_MESSAGE_HANDLER(ShellViewHostMsg_AllocateId, OnAllocateId);
118+
IPC_MESSAGE_HANDLER(ShellViewHostMsg_SetForceClose, OnSetForceClose);
118119
IPC_MESSAGE_UNHANDLED(handled = false)
119120
IPC_END_MESSAGE_MAP()
120121

@@ -281,17 +282,14 @@ void DispatcherHost::OnCreateShell(const std::string& url,
281282
WebContents* web_contents = content::WebContentsImpl::CreateWithOpener(
282283
create_params,
283284
static_cast<content::WebContentsImpl*>(base_web_contents));
284-
content::Shell* new_shell =
285-
content::Shell::Create(base_web_contents,
285+
286+
content::Shell::Create(base_web_contents,
286287
GURL(url),
287288
new_manifest.get(),
288289
web_contents);
289290

290291
if (new_renderer) {
291292
browser_context->set_pinning_renderer(true);
292-
// since the new-instance shell is always bound
293-
// there would be 'Close' event cannot reach dest
294-
new_shell->set_force_close(true);
295293
}
296294

297295
*routing_id = web_contents->GetRoutingID();
@@ -307,4 +305,11 @@ void DispatcherHost::OnAllocateId(int * ret) {
307305
*ret = AllocateId();
308306
}
309307

308+
void DispatcherHost::OnSetForceClose(bool force, int* ret) {
309+
content::Shell* shell =
310+
content::Shell::FromRenderViewHost(render_view_host());
311+
shell->set_force_close(force);
312+
*ret = 0;
313+
}
314+
310315
} // namespace nwapi

src/api/dispatcher_host.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ class DispatcherHost : public content::WebContentsObserver {
117117
const base::DictionaryValue& manifest,
118118
int* routing_id);
119119
void OnAllocateId(int* ret);
120+
void OnSetForceClose(bool force, int* ret);
121+
120122
DISALLOW_COPY_AND_ASSIGN(DispatcherHost);
121123
};
122124

src/renderer/shell_content_renderer_client.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,16 @@ void ShellContentRendererClient::InstallNodeSymbols(
347347
"process.versions['chromium'] = '" CHROME_VERSION "';"
348348
));
349349
script->Run();
350+
v8::Local<v8::Script> script2 = v8::Script::New(v8::String::New(
351+
" nwDispatcher.requireNwGui().Window.get();"
352+
));
353+
script2->Run();
354+
} else {
355+
int ret;
356+
RenderViewImpl* render_view = RenderViewImpl::FromWebView(frame->view());
357+
358+
render_view->Send(new ShellViewHostMsg_SetForceClose(
359+
render_view->GetRoutingID(), true, &ret));
350360
}
351361
}
352362

0 commit comments

Comments
 (0)