Skip to content

Commit 6fc211f

Browse files
committed
nw.currentWindowInternal.getCurrent implementation
This function returns chrome.windows.Window object in sync way
1 parent 61b5f58 commit 6fc211f

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/api/nw_current_window_internal.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace nw.currentWindowInternal {
4343
static DOMString getTitleInternal();
4444
static void setTitleInternal(DOMString title);
4545
static object getWinParamInternal();
46+
static object getCurrent(optional object options);
4647
static void getPrinters(GetPrintersCallback callback);
4748
static void setPrintSettingsInternal(optional object options);
4849
};

src/api/nw_window_api.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,31 @@ bool NwCurrentWindowInternalSetPrintSettingsInternalFunction::RunNWSync(base::Li
690690
return true;
691691
}
692692

693+
bool NwCurrentWindowInternalGetCurrentFunction::RunNWSync(base::ListValue* response, std::string* ret_error) {
694+
std::unique_ptr<windows::GetCurrent::Params> params(
695+
windows::GetCurrent::Params::Create(*args_));
696+
EXTENSION_FUNCTION_VALIDATE(params.get());
697+
698+
ApiParameterExtractor<windows::GetCurrent::Params> extractor(params.get());
699+
Browser* browser = nullptr;
700+
std::string error;
701+
if (!windows_util::GetBrowserFromWindowID(
702+
this, extension_misc::kCurrentWindowId, extractor.type_filters(),
703+
&browser, &error)) {
704+
*ret_error = error;
705+
return false;
706+
}
707+
708+
ExtensionTabUtil::PopulateTabBehavior populate_tab_behavior =
709+
extractor.populate_tabs() ? ExtensionTabUtil::kPopulateTabs
710+
: ExtensionTabUtil::kDontPopulateTabs;
711+
std::unique_ptr<base::DictionaryValue> windows =
712+
ExtensionTabUtil::CreateWindowValueForExtension(*browser, extension(),
713+
populate_tab_behavior);
714+
response->Append(std::move(windows));
715+
return true;
716+
}
717+
693718
bool NwCurrentWindowInternalGetWinParamInternalFunction::RunNWSync(base::ListValue* response, std::string* error) {
694719
AppWindow* app_window = getAppWindow(this);
695720

src/api/nw_window_api.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,16 @@ class NwCurrentWindowInternalGetWinParamInternalFunction : public NWSyncExtensio
295295
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.getWinParamInternal", UNKNOWN)
296296
};
297297

298+
class NwCurrentWindowInternalGetCurrentFunction : public NWSyncExtensionFunction {
299+
public:
300+
NwCurrentWindowInternalGetCurrentFunction() {}
301+
bool RunNWSync(base::ListValue* response, std::string* error) override;
302+
303+
protected:
304+
~NwCurrentWindowInternalGetCurrentFunction() override {}
305+
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.getCurrent", UNKNOWN)
306+
};
307+
298308
class NwCurrentWindowInternalGetPrintersFunction : public UIThreadExtensionFunction {
299309
public:
300310
NwCurrentWindowInternalGetPrintersFunction() {}

0 commit comments

Comments
 (0)