Skip to content

Commit 90d2c43

Browse files
committed
nw2: fix crash on Window.setShadow()
Fix nwjs#7232
1 parent 5c1fa98 commit 90d2c43

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

src/api/nw_current_window_internal.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace nw.currentWindowInternal {
2323

2424
interface Functions {
2525
static void close(optional boolean force, optional long id);
26-
static void setShadow(boolean shadow);
26+
static void setShadowInternal(boolean shadow, optional long id);
2727
static void showDevToolsInternal(optional ShowDevToolsCallback callback);
2828
static void showDevTools2Internal(long id, optional ShowDevToolsCallback callback);
2929
static void closeDevTools();

src/api/nw_window_api.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,13 +821,21 @@ bool NwCurrentWindowInternalGetTitleInternalFunction::RunNWSync(base::ListValue*
821821
}
822822

823823
ExtensionFunction::ResponseAction
824-
NwCurrentWindowInternalSetShadowFunction::Run() {
824+
NwCurrentWindowInternalSetShadowInternalFunction::Run() {
825825
#if defined(OS_MACOSX)
826826
EXTENSION_FUNCTION_VALIDATE(args_);
827827
bool shadow;
828828
EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(0, &shadow));
829-
AppWindow* window = getAppWindow(this);
830-
SetShadowOnWindow(window->GetNativeWindow().GetNativeNSWindow(), shadow);
829+
if (base::FeatureList::IsEnabled(::features::kNWNewWin)) {
830+
int id = 0;
831+
args_->GetInteger(1, &id);
832+
Browser* browser = getBrowser(this, id);
833+
if (browser)
834+
SetShadowOnWindow(browser->window()->GetNativeWindow().GetNativeNSWindow(), shadow);
835+
} else {
836+
AppWindow* window = getAppWindow(this);
837+
SetShadowOnWindow(window->GetNativeWindow().GetNativeNSWindow(), shadow);
838+
}
831839
#endif
832840
return RespondNow(NoArguments());
833841
}

src/api/nw_window_api.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,19 @@ class NwCurrentWindowInternalSetMenuFunction : public NWSyncExtensionFunction {
136136
DISALLOW_COPY_AND_ASSIGN(NwCurrentWindowInternalSetMenuFunction);
137137
};
138138

139-
class NwCurrentWindowInternalSetShadowFunction : public ExtensionFunction {
139+
class NwCurrentWindowInternalSetShadowInternalFunction : public ExtensionFunction {
140140
public:
141-
NwCurrentWindowInternalSetShadowFunction(){}
141+
NwCurrentWindowInternalSetShadowInternalFunction(){}
142142

143143
protected:
144-
~NwCurrentWindowInternalSetShadowFunction() override {}
144+
~NwCurrentWindowInternalSetShadowInternalFunction() override {}
145145
#if defined(OS_MACOSX)
146146
void SetShadowOnWindow(NSWindow *window, bool shadow);
147147
#endif
148148

149149
// ExtensionFunction:
150150
ResponseAction Run() override;
151-
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.setShadow", UNKNOWN)
151+
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.setShadowInternal", UNKNOWN)
152152
};
153153

154154
class NwCurrentWindowInternalSetBadgeLabelFunction : public ExtensionFunction {

src/api/nw_window_api_mac.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ - (void)drawRect:(NSRect)dirtyRect {
4747

4848
namespace extensions {
4949

50-
void NwCurrentWindowInternalSetShadowFunction::SetShadowOnWindow(NSWindow *window, bool shadow) {
50+
void NwCurrentWindowInternalSetShadowInternalFunction::SetShadowOnWindow(NSWindow *window, bool shadow) {
5151
window.hasShadow = shadow;
5252
}
5353

src/resources/api_nw_newwin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ NWWindow.prototype.removeAllListeners = function (event) {
309309
};
310310

311311
NWWindow.prototype.setShadow = function(shadow) {
312-
currentNWWindowInternal.setShadow(shadow);
312+
currentNWWindowInternal.setShadowInternal(shadow, this.cWindow.id);
313313
};
314314

315315
NWWindow.prototype.showDevTools = function(frm, callback) {

src/resources/api_nw_window.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ apiBridge.registerCustomHook(function(bindingsAPI) {
344344
};
345345

346346
NWWindow.prototype.setShadow = function(shadow) {
347-
currentNWWindowInternal.setShadow(shadow);
347+
currentNWWindowInternal.setShadowInternal(shadow);
348348
}
349349

350350
NWWindow.prototype.showDevTools = function(frm, callback) {

0 commit comments

Comments
 (0)