Skip to content

Commit 9761605

Browse files
committed
nw2: kiosk mode support
1 parent 215d14d commit 9761605

File tree

5 files changed

+98
-24
lines changed

5 files changed

+98
-24
lines changed

src/api/nw_current_window_internal.idl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ namespace nw.currentWindowInternal {
3030
static void setBadgeLabel(DOMString badge);
3131
static void requestAttentionInternal(long count);
3232
static void setProgressBar(double progress);
33-
static void enterKioskMode();
34-
static void leaveKioskMode();
35-
static void toggleKioskMode();
33+
static void enterKioskModeInternal(optional long id);
34+
static void leaveKioskModeInternal(optional long id);
35+
static void toggleKioskModeInternal(optional long id);
3636
static bool isKioskInternal();
3737
static void capturePageInternal(optional CapturePageOptions options, optional CapturePageCallback callback);
3838
static void clearMenu(optional long win);

src/api/nw_window_api.cc

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -769,27 +769,67 @@ bool NwCurrentWindowInternalSetZoomFunction::RunNWSync(base::ListValue* response
769769
}
770770

771771
ExtensionFunction::ResponseAction
772-
NwCurrentWindowInternalEnterKioskModeFunction::Run() {
773-
AppWindow* window = getAppWindow(this);
774-
window->ForcedFullscreen();
772+
NwCurrentWindowInternalEnterKioskModeInternalFunction::Run() {
773+
if (base::FeatureList::IsEnabled(::features::kNWNewWin)) {
774+
int id = 0;
775+
args_->GetInteger(0, &id);
776+
Browser* browser = getBrowser(this, id);
777+
if (browser) {
778+
BrowserFrame* frame = BrowserView::GetBrowserViewForBrowser(browser)->frame();
779+
frame->SetFullscreen(true);
780+
}
781+
} else {
782+
AppWindow* window = getAppWindow(this);
783+
window->ForcedFullscreen();
784+
}
775785
#if defined(OS_MACOSX)
776786
NWSetNSAppKioskOptions();
777787
#endif
778788
return RespondNow(NoArguments());
779789
}
780790

781791
ExtensionFunction::ResponseAction
782-
NwCurrentWindowInternalLeaveKioskModeFunction::Run() {
792+
NwCurrentWindowInternalLeaveKioskModeInternalFunction::Run() {
783793
#if defined(OS_MACOSX)
784794
NWRestoreNSAppKioskOptions();
785795
#endif
796+
if (base::FeatureList::IsEnabled(::features::kNWNewWin)) {
797+
int id = 0;
798+
args_->GetInteger(0, &id);
799+
Browser* browser = getBrowser(this, id);
800+
if (browser) {
801+
BrowserFrame* frame = BrowserView::GetBrowserViewForBrowser(browser)->frame();
802+
frame->Restore();
803+
return RespondNow(NoArguments());
804+
}
805+
}
786806
AppWindow* window = getAppWindow(this);
787807
window->Restore();
788808
return RespondNow(NoArguments());
789809
}
790810

791811
ExtensionFunction::ResponseAction
792-
NwCurrentWindowInternalToggleKioskModeFunction::Run() {
812+
NwCurrentWindowInternalToggleKioskModeInternalFunction::Run() {
813+
if (base::FeatureList::IsEnabled(::features::kNWNewWin)) {
814+
int id = 0;
815+
args_->GetInteger(0, &id);
816+
Browser* browser = getBrowser(this, id);
817+
if (browser) {
818+
BrowserFrame* frame = BrowserView::GetBrowserViewForBrowser(browser)->frame();
819+
if (frame->IsFullscreen()) {
820+
frame->Restore();
821+
#if defined(OS_MACOSX)
822+
NWRestoreNSAppKioskOptions();
823+
#endif
824+
} else {
825+
frame->SetFullscreen(true);
826+
#if defined(OS_MACOSX)
827+
NWSetNSAppKioskOptions();
828+
#endif
829+
}
830+
return RespondNow(NoArguments());
831+
}
832+
}
793833
AppWindow* window = getAppWindow(this);
794834
if (window->IsFullscreen() || window->IsForcedFullscreen()) {
795835
#if defined(OS_MACOSX)
@@ -806,6 +846,16 @@ NwCurrentWindowInternalToggleKioskModeFunction::Run() {
806846
}
807847

808848
bool NwCurrentWindowInternalIsKioskInternalFunction::RunNWSync(base::ListValue* response, std::string* error) {
849+
if (base::FeatureList::IsEnabled(::features::kNWNewWin)) {
850+
int id = 0;
851+
args_->GetInteger(0, &id);
852+
Browser* browser = getBrowser(this, id);
853+
if (browser) {
854+
BrowserFrame* frame = BrowserView::GetBrowserViewForBrowser(browser)->frame();
855+
response->AppendBoolean((frame->IsFullscreen()));
856+
return true;
857+
}
858+
}
809859
AppWindow* window = getAppWindow(this);
810860
if (window->IsFullscreen() || window->IsForcedFullscreen())
811861
response->AppendBoolean(true);

src/api/nw_window_api.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,40 +223,40 @@ class NwCurrentWindowInternalSetZoomFunction : public NWSyncExtensionFunction {
223223
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.setZoom", UNKNOWN)
224224
};
225225

226-
class NwCurrentWindowInternalEnterKioskModeFunction : public ExtensionFunction {
226+
class NwCurrentWindowInternalEnterKioskModeInternalFunction : public ExtensionFunction {
227227
public:
228-
NwCurrentWindowInternalEnterKioskModeFunction() {}
228+
NwCurrentWindowInternalEnterKioskModeInternalFunction() {}
229229

230230
protected:
231-
~NwCurrentWindowInternalEnterKioskModeFunction() override {}
231+
~NwCurrentWindowInternalEnterKioskModeInternalFunction() override {}
232232

233233
// ExtensionFunction:
234234
ResponseAction Run() override;
235-
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.enterKioskMode", UNKNOWN)
235+
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.enterKioskModeInternal", UNKNOWN)
236236
};
237237

238-
class NwCurrentWindowInternalLeaveKioskModeFunction : public ExtensionFunction {
238+
class NwCurrentWindowInternalLeaveKioskModeInternalFunction : public ExtensionFunction {
239239
public:
240-
NwCurrentWindowInternalLeaveKioskModeFunction() {}
240+
NwCurrentWindowInternalLeaveKioskModeInternalFunction() {}
241241

242242
protected:
243-
~NwCurrentWindowInternalLeaveKioskModeFunction() override {}
243+
~NwCurrentWindowInternalLeaveKioskModeInternalFunction() override {}
244244

245245
// ExtensionFunction:
246246
ResponseAction Run() override;
247-
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.leaveKioskMode", UNKNOWN)
247+
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.leaveKioskModeInternal", UNKNOWN)
248248
};
249249

250-
class NwCurrentWindowInternalToggleKioskModeFunction : public ExtensionFunction {
250+
class NwCurrentWindowInternalToggleKioskModeInternalFunction : public ExtensionFunction {
251251
public:
252-
NwCurrentWindowInternalToggleKioskModeFunction() {}
252+
NwCurrentWindowInternalToggleKioskModeInternalFunction() {}
253253

254254
protected:
255-
~NwCurrentWindowInternalToggleKioskModeFunction() override {}
255+
~NwCurrentWindowInternalToggleKioskModeInternalFunction() override {}
256256

257257
// ExtensionFunction:
258258
ResponseAction Run() override;
259-
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.toggleKioskMode", UNKNOWN)
259+
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.toggleKioskModeInternal", UNKNOWN)
260260
};
261261

262262
class NwCurrentWindowInternalIsKioskInternalFunction : public NWSyncExtensionFunction {

src/resources/api_nw_newwin.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,18 @@ NWWindow.prototype.setShadow = function(shadow) {
312312
currentNWWindowInternal.setShadowInternal(shadow, this.cWindow.id);
313313
};
314314

315+
NWWindow.prototype.enterKioskMode = function() {
316+
currentNWWindowInternal.enterKioskModeInternal(this.cWindow.id);
317+
};
318+
319+
NWWindow.prototype.leaveKioskMode = function() {
320+
currentNWWindowInternal.leaveKioskModeInternal(this.cWindow.id);
321+
};
322+
323+
NWWindow.prototype.toggleKioskMode = function() {
324+
currentNWWindowInternal.toggleKioskModeInternal(this.cWindow.id);
325+
};
326+
315327
NWWindow.prototype.showDevTools = function(frm, callback) {
316328
var id = '';
317329
if (typeof frm === 'string')
@@ -547,13 +559,13 @@ Object.defineProperty(NWWindow.prototype, 'isTransparent', {
547559
});
548560
Object.defineProperty(NWWindow.prototype, 'isKioskMode', {
549561
get: function() {
550-
return currentNWWindowInternal.isKioskInternal();
562+
return currentNWWindowInternal.isKioskInternal(this.cWindow.id);
551563
},
552564
set: function(val) {
553565
if (val)
554-
currentNWWindowInternal.enterKioskMode();
566+
currentNWWindowInternal.enterKioskModeInternal(this.cWindow.id);
555567
else
556-
currentNWWindowInternal.leaveKioskMode();
568+
currentNWWindowInternal.leaveKioskModeInternal(this.cWindow.id);
557569
}
558570
});
559571
Object.defineProperty(NWWindow.prototype, 'isFullscreen', {

src/resources/api_nw_window.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,19 @@ apiBridge.registerCustomHook(function(bindingsAPI) {
345345

346346
NWWindow.prototype.setShadow = function(shadow) {
347347
currentNWWindowInternal.setShadowInternal(shadow);
348-
}
348+
};
349+
350+
NWWindow.prototype.enterKioskMode = function() {
351+
currentNWWindowInternal.enterKioskModeInternal();
352+
};
353+
354+
NWWindow.prototype.leaveKioskMode = function() {
355+
currentNWWindowInternal.leaveKioskModeInternal();
356+
};
357+
358+
NWWindow.prototype.toggleKioskMode = function() {
359+
currentNWWindowInternal.toggleKioskModeInternal();
360+
};
349361

350362
NWWindow.prototype.showDevTools = function(frm, callback) {
351363
var id = '';

0 commit comments

Comments
 (0)