Skip to content

Commit 607af60

Browse files
committed
newwin mode: nw.Window API: nw.Window.get, open and loaded event
1 parent 6fc211f commit 607af60

File tree

3 files changed

+787
-2
lines changed

3 files changed

+787
-2
lines changed

src/api/nw_window.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ namespace nw.Window {
8080
static void print(optional object options);
8181

8282
object appWindow;
83+
object cWindow;
8384
object window;
8485
object menu;
8586
long x;

src/api/nw_window_api.cc

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include "content/public/browser/render_widget_host.h"
88
#include "chrome/browser/devtools/devtools_window.h"
99
#include "chrome/browser/extensions/devtools_util.h"
10+
#include "chrome/browser/extensions/extension_tab_util.h"
11+
#include "chrome/browser/extensions/window_controller.h"
12+
#include "chrome/browser/extensions/api/tabs/windows_util.h"
13+
#include "chrome/browser/ui/browser.h"
1014
#include "components/zoom/zoom_controller.h"
1115
#include "content/nw/src/api/menu/menu.h"
1216
#include "content/nw/src/api/object_manager.h"
@@ -102,11 +106,41 @@ printing::PrinterList EnumeratePrintersAsync() {
102106
}
103107

104108
namespace extensions {
109+
110+
namespace windows = api::windows;
111+
namespace tabs = api::tabs;
112+
113+
using api::extension_types::InjectDetails;
114+
105115
namespace {
106116

107117
const char kNoAssociatedAppWindow[] =
108118
"The context from which the function was called did not have an "
109119
"associated app window.";
120+
121+
template <typename T>
122+
class ApiParameterExtractor {
123+
public:
124+
explicit ApiParameterExtractor(T* params) : params_(params) {}
125+
~ApiParameterExtractor() {}
126+
127+
bool populate_tabs() {
128+
if (params_->get_info.get() && params_->get_info->populate.get())
129+
return *params_->get_info->populate;
130+
return false;
131+
}
132+
133+
WindowController::TypeFilter type_filters() {
134+
if (params_->get_info.get() && params_->get_info->window_types.get())
135+
return WindowController::GetFilterFromWindowTypes(
136+
*params_->get_info->window_types);
137+
return WindowController::kNoWindowFilter;
138+
}
139+
140+
private:
141+
T* params_;
142+
};
143+
110144
}
111145

112146
static AppWindow* getAppWindow(UIThreadExtensionFunction* func) {
@@ -622,9 +656,25 @@ bool NwCurrentWindowInternalIsKioskInternalFunction::RunNWSync(base::ListValue*
622656
return true;
623657
}
624658

625-
bool NwCurrentWindowInternalGetTitleInternalFunction::RunNWSync(base::ListValue* response, std::string* error) {
659+
bool NwCurrentWindowInternalGetTitleInternalFunction::RunNWSync(base::ListValue* response, std::string* ret_error) {
626660
AppWindow* window = getAppWindow(this);
627-
response->AppendString(window->title_override());
661+
if (window) {
662+
response->AppendString(window->title_override());
663+
return true;
664+
}
665+
Browser* browser = nullptr;
666+
std::string error;
667+
if (!windows_util::GetBrowserFromWindowID(
668+
this, extension_misc::kCurrentWindowId, WindowController::GetAllWindowFilter(),
669+
&browser, &error)) {
670+
*ret_error = error;
671+
return false;
672+
}
673+
if (!browser) {
674+
*ret_error = "no window found";
675+
return false;
676+
}
677+
response->AppendString(browser->GetWindowTitleForCurrentTab(false));
628678
return true;
629679
}
630680

0 commit comments

Comments
 (0)