Skip to content

Commit 6baf3a8

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 64c064e commit 6baf3a8

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
@@ -114,6 +114,7 @@ bool DispatcherHost::OnMessageReceived(const IPC::Message& message) {
114114
IPC_MESSAGE_HANDLER(ShellViewHostMsg_GetShellId, OnGetShellId);
115115
IPC_MESSAGE_HANDLER(ShellViewHostMsg_CreateShell, OnCreateShell);
116116
IPC_MESSAGE_HANDLER(ShellViewHostMsg_AllocateId, OnAllocateId);
117+
IPC_MESSAGE_HANDLER(ShellViewHostMsg_SetForceClose, OnSetForceClose);
117118
IPC_MESSAGE_UNHANDLED(handled = false)
118119
IPC_END_MESSAGE_MAP()
119120

@@ -272,17 +273,14 @@ void DispatcherHost::OnCreateShell(const std::string& url,
272273
WebContents* web_contents = content::WebContentsImpl::CreateWithOpener(
273274
create_params,
274275
static_cast<content::WebContentsImpl*>(base_web_contents));
275-
content::Shell* new_shell =
276-
content::Shell::Create(base_web_contents,
276+
277+
content::Shell::Create(base_web_contents,
277278
GURL(url),
278279
new_manifest.get(),
279280
web_contents);
280281

281282
if (new_renderer) {
282283
browser_context->set_pinning_renderer(true);
283-
// since the new-instance shell is always bound
284-
// there would be 'Close' event cannot reach dest
285-
new_shell->set_force_close(true);
286284
}
287285

288286
*routing_id = web_contents->GetRoutingID();
@@ -298,4 +296,11 @@ void DispatcherHost::OnAllocateId(int * ret) {
298296
*ret = AllocateId();
299297
}
300298

299+
void DispatcherHost::OnSetForceClose(bool force, int* ret) {
300+
content::Shell* shell =
301+
content::Shell::FromRenderViewHost(render_view_host());
302+
shell->set_force_close(force);
303+
*ret = 0;
304+
}
305+
301306
} // namespace nwapi

src/api/dispatcher_host.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class DispatcherHost : public content::RenderViewHostObserver {
113113
const base::DictionaryValue& manifest,
114114
int* routing_id);
115115
void OnAllocateId(int* ret);
116+
void OnSetForceClose(bool force, int* ret);
117+
116118
DISALLOW_COPY_AND_ASSIGN(DispatcherHost);
117119
};
118120

src/renderer/shell_content_renderer_client.cc

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

0 commit comments

Comments
 (0)