Skip to content

Commit ec57981

Browse files
committed
nw2: port App.closeAppWindows and App.quit
Ref nwjs#5875
1 parent 5395645 commit ec57981

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/api/nw_app_api.cc

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include "content/nw/src/api/nw_app_api.h"
22

3+
#include "chrome/browser/lifetime/browser_close_manager.h"
4+
#include "chrome/browser/lifetime/application_lifetime.h"
5+
#include "content/public/common/content_features.h"
6+
37
#include "base/command_line.h"
48
#include "base/memory/ptr_util.h"
59
#include "base/task/post_task.h"
@@ -50,19 +54,31 @@ NwAppQuitFunction::NwAppQuitFunction() {
5054
NwAppQuitFunction::~NwAppQuitFunction() {
5155
}
5256

57+
void NwAppQuitFunction::DoJob(ExtensionService* service, std::string extension_id) {
58+
if (base::FeatureList::IsEnabled(::features::kNWNewWin)) {
59+
chrome::CloseAllBrowsersAndQuit(true);
60+
return;
61+
}
62+
base::MessageLoop::current()->task_runner()->PostTask(
63+
FROM_HERE,
64+
base::Bind(&ExtensionService::TerminateExtension,
65+
service->AsWeakPtr(),
66+
extension_id));
67+
}
68+
5369
ExtensionFunction::ResponseAction
5470
NwAppQuitFunction::Run() {
55-
ExtensionService* service =
56-
ExtensionSystem::Get(browser_context())->extension_service();
71+
ExtensionService* service = ExtensionSystem::Get(browser_context())->extension_service();
5772
base::MessageLoop::current()->task_runner()->PostTask(
58-
FROM_HERE,
59-
base::Bind(&ExtensionService::TerminateExtension,
60-
service->AsWeakPtr(),
61-
extension_id()));
73+
FROM_HERE,
74+
base::Bind(&NwAppQuitFunction::DoJob, service, extension()->id()));
6275
return RespondNow(NoArguments());
6376
}
6477

6578
void NwAppCloseAllWindowsFunction::DoJob(AppWindowRegistry* registry, std::string id) {
79+
if (base::FeatureList::IsEnabled(::features::kNWNewWin)) {
80+
chrome::CloseAllBrowsers();
81+
}
6682
AppWindowRegistry::AppWindowList windows =
6783
registry->GetAppWindowsForApp(id);
6884

src/api/nw_app_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
namespace extensions {
1111
class AppWindowRegistry;
12+
class ExtensionService;
1213

1314
class NwAppQuitFunction : public UIThreadExtensionFunction {
1415
public:
1516
NwAppQuitFunction();
1617

18+
static void DoJob(extensions::ExtensionService* service, std::string extension_id);
1719
protected:
1820
~NwAppQuitFunction() override;
1921

0 commit comments

Comments
 (0)