Skip to content

Commit 9f2c531

Browse files
committed
Fix nwjs#7609: mixed_context window option for new_instance window
1 parent ad0d861 commit 9f2c531

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

src/api/nw_window.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace nw.Window {
3535
[nodoc] boolean? kiosk;
3636
[nodoc] boolean? focus;
3737
[nodoc] boolean? new_instance;
38+
[nodoc] boolean? mixed_context;
3839
[nodoc] boolean? show_in_taskbar;
3940
[nodoc] DOMString? title;
4041
[nodoc] DOMString? position;

src/browser/nw_content_browser_hooks.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace nw {
5454
namespace {
5555

5656
bool g_pinning_renderer = true;
57+
bool g_mixed_context = false;
5758
bool g_in_webview_apply_attr = false;
5859
bool g_in_webview_apply_attr_allow_nw = false;
5960
} //namespace
@@ -192,6 +193,14 @@ void SetPinningRenderer(bool pin) {
192193
g_pinning_renderer = pin;
193194
}
194195

196+
bool MixedContext() {
197+
return g_mixed_context;
198+
}
199+
200+
void SetMixedContext(bool mixed) {
201+
g_mixed_context = mixed;
202+
}
203+
195204
void SetInWebViewApplyAttr(bool flag, bool allow_nw) {
196205
g_in_webview_apply_attr = flag;
197206
g_in_webview_apply_attr_allow_nw = allow_nw;

src/browser/nw_content_browser_hooks.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ CONTENT_EXPORT void OverrideWebkitPrefsHook(content::RenderViewHost* rvh, conten
4848
// content/browser/renderer_host/render_process_host_impl.cc
4949
// content/browser/site_instance_impl.cc
5050
CONTENT_EXPORT bool PinningRenderer();
51+
CONTENT_EXPORT bool MixedContext();
5152

5253
#if defined(OS_MAC)
5354
// ref in chrome/browser/app_controller_mac.mm
@@ -62,6 +63,7 @@ CONTENT_EXPORT bool GetPackageImage(nw::Package* package,
6263
gfx::Image* image);
6364
// ref in extensions/browser/api/app_window/app_window_api.cc
6465
CONTENT_EXPORT void SetPinningRenderer(bool pin);
66+
CONTENT_EXPORT void SetMixedContext(bool);
6567

6668
// browser
6769
// ref in content/nw/src/api/tray/tray_aura.cc

src/renderer/nw_extensions_renderer_hooks.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ void ContextCreationHook(blink::WebLocalFrame* frame, ScriptContext* context) {
219219

220220
if (extension)
221221
extension->manifest()->GetBoolean(manifest_keys::kNWJSMixedContext, &mixed_context);
222+
if (!mixed_context) {
223+
mixed_context = command_line.HasSwitch("mixed-context");
224+
}
222225
// handle navigation in webview #5622
223226
if (nwjs_guest_nw)
224227
mixed_context = true;

src/resources/api_nw_newwin.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,12 @@ apiBridge.registerCustomHook(function(bindingsAPI) {
809809
options.new_instance = true;
810810
options.setSelfAsOpener = false;
811811
}
812+
if (params.mixed_context === true) {
813+
if (params.new_instance !== true) {
814+
throw new Error('mixed_context should be set with new_instance in nw.Window.open');
815+
}
816+
options.mixed_context = true;
817+
}
812818
if (params.position)
813819
options.position = params.position;
814820
if (params.title)

0 commit comments

Comments
 (0)