Skip to content

Commit 1d295e8

Browse files
committed
Merge branch 'nw49' into nw50
2 parents 5cc4737 + a6496dd commit 1d295e8

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

src/api/nw_current_window_internal.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace nw.currentWindowInternal {
3434
static void leaveKioskModeInternal(optional long id);
3535
static void toggleKioskModeInternal(optional long id);
3636
static bool isKioskInternal(optional long id);
37-
static void capturePageInternal(optional CapturePageOptions options, optional CapturePageCallback callback);
37+
static void capturePageInternal(long id, optional CapturePageOptions options, optional CapturePageCallback callback);
3838
static void clearMenu(optional long win);
3939
static MenuPatch[] setMenu(long id, optional long winId);
4040
static void reloadIgnoringCache();

src/api/nw_window_api.cc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,26 @@ NwCurrentWindowInternalCapturePageInternalFunction::Run() {
320320
EXTENSION_FUNCTION_VALIDATE(args_);
321321

322322
std::unique_ptr<ImageDetails> image_details;
323-
if (args_->GetSize() > 0) {
323+
WebContents* contents = nullptr;
324+
325+
if (args_->GetSize() > 1) {
324326
base::Value* spec = NULL;
325-
EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &spec) && spec);
327+
EXTENSION_FUNCTION_VALIDATE(args_->Get(1, &spec) && spec);
326328
image_details = ImageDetails::FromValue(*spec);
327329
}
328330

329-
content::RenderFrameHost* rfh = render_frame_host();
330-
WebContents* contents = content::WebContents::FromRenderFrameHost(rfh);
331+
if (base::FeatureList::IsEnabled(::features::kNWNewWin)) {
332+
int id = 0;
333+
args_->GetInteger(0, &id);
334+
Browser* browser = getBrowser(this, id);
335+
if (!browser) {
336+
return RespondNow(Error("no browser window found"));
337+
}
338+
contents = browser->tab_strip_model()->GetActiveWebContents();
339+
} else {
340+
content::RenderFrameHost* rfh = render_frame_host();
341+
contents = content::WebContents::FromRenderFrameHost(rfh);
342+
}
331343
if (!contents)
332344
return RespondNow(Error("contents is null"));
333345

src/resources/api_nw_newwin.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ var nwWinEventsMap = {
5454
};
5555

5656
var nwWrapEventsMap = {
57-
'loaded': 'LoadingStateChanged',
5857
'new-win-policy': 'onNewWinPolicy',
5958
'navigation': 'onNavigation'
6059
};
@@ -265,6 +264,14 @@ NWWindow.prototype.on = function (event, callback, record) {
265264
return this;
266265
};
267266
NWWindow.prototype.removeListener = function (event, callback) {
267+
if (event === 'loaded') {
268+
for (let l of chrome.tabs.onUpdated.getListeners()) {
269+
if (l.listener && l.listener === callback) {
270+
chrome.tabs.onUpdated.removeListener(l);
271+
return this;
272+
}
273+
}
274+
}
268275
if (nwWinEventsMap.hasOwnProperty(event)) {
269276
for (let l of this[nwWinEventsMap[event]].getListeners()) {
270277
if (l.listener && l.listener === callback) {
@@ -320,6 +327,12 @@ NWWindow.prototype.removeAllListeners = function (event) {
320327
}
321328
return this;
322329
}
330+
if (event === 'loaded') {
331+
for (let l of chrome.tabs.onUpdated.getListeners()) {
332+
chrome.tabs.onUpdated.removeListener(l);
333+
}
334+
return this;
335+
}
323336
return this;
324337
};
325338

@@ -363,6 +376,7 @@ NWWindow.prototype.showDevTools = function(frm, callback) {
363376
nwNatives.setDevToolsJail(f);
364377
currentNWWindowInternal.showDevTools2Internal(this.cWindow.id, callback);
365378
};
379+
366380
NWWindow.prototype.capturePage = function (callback, options) {
367381
var cb = callback;
368382
if (!options)
@@ -383,7 +397,8 @@ NWWindow.prototype.capturePage = function (callback, options) {
383397
};
384398
cb = cb.bind(undefined, options.datatype);
385399
}
386-
currentNWWindowInternal.capturePageInternal(options, cb);
400+
this.cWindow = currentNWWindowInternal.getCurrent(this.cWindow.id, {'populate': true});
401+
currentNWWindowInternal.capturePageInternal(this.cWindow.id, options, cb);
387402
};
388403

389404
function sendCommand(tabId, name, options) {

src/resources/api_nw_window.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ apiBridge.registerCustomHook(function(bindingsAPI) {
403403
};
404404
cb = cb.bind(undefined, options.datatype);
405405
}
406-
currentNWWindowInternal.capturePageInternal(options, cb);
406+
currentNWWindowInternal.capturePageInternal(0, options, cb);
407407
};
408408
NWWindow.prototype.reload = function () {
409409
this.appWindow.contentWindow.location.reload();

0 commit comments

Comments
 (0)