diff --git a/src/api/nw_current_window_internal.idl b/src/api/nw_current_window_internal.idl index 6761e4d1eb..64acf40dbe 100644 --- a/src/api/nw_current_window_internal.idl +++ b/src/api/nw_current_window_internal.idl @@ -34,7 +34,7 @@ namespace nw.currentWindowInternal { static void leaveKioskModeInternal(optional long id); static void toggleKioskModeInternal(optional long id); static bool isKioskInternal(optional long id); - static void capturePageInternal(optional CapturePageOptions options, optional CapturePageCallback callback); + static void capturePageInternal(long id, optional CapturePageOptions options, optional CapturePageCallback callback); static void clearMenu(optional long win); static MenuPatch[] setMenu(long id, optional long winId); static void reloadIgnoringCache(); diff --git a/src/api/nw_window_api.cc b/src/api/nw_window_api.cc index e3ea1cc95f..186cce038f 100644 --- a/src/api/nw_window_api.cc +++ b/src/api/nw_window_api.cc @@ -320,14 +320,26 @@ NwCurrentWindowInternalCapturePageInternalFunction::Run() { EXTENSION_FUNCTION_VALIDATE(args_); std::unique_ptr image_details; - if (args_->GetSize() > 0) { + WebContents* contents = nullptr; + + if (args_->GetSize() > 1) { base::Value* spec = NULL; - EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &spec) && spec); + EXTENSION_FUNCTION_VALIDATE(args_->Get(1, &spec) && spec); image_details = ImageDetails::FromValue(*spec); } - content::RenderFrameHost* rfh = render_frame_host(); - WebContents* contents = content::WebContents::FromRenderFrameHost(rfh); + if (base::FeatureList::IsEnabled(::features::kNWNewWin)) { + int id = 0; + args_->GetInteger(0, &id); + Browser* browser = getBrowser(this, id); + if (!browser) { + return RespondNow(Error("no browser window found")); + } + contents = browser->tab_strip_model()->GetActiveWebContents(); + } else { + content::RenderFrameHost* rfh = render_frame_host(); + contents = content::WebContents::FromRenderFrameHost(rfh); + } if (!contents) return RespondNow(Error("contents is null")); diff --git a/src/resources/api_nw_newwin.js b/src/resources/api_nw_newwin.js index f7ea45ed9e..7cddb47654 100644 --- a/src/resources/api_nw_newwin.js +++ b/src/resources/api_nw_newwin.js @@ -363,6 +363,7 @@ NWWindow.prototype.showDevTools = function(frm, callback) { nwNatives.setDevToolsJail(f); currentNWWindowInternal.showDevTools2Internal(this.cWindow.id, callback); }; + NWWindow.prototype.capturePage = function (callback, options) { var cb = callback; if (!options) @@ -383,7 +384,8 @@ NWWindow.prototype.capturePage = function (callback, options) { }; cb = cb.bind(undefined, options.datatype); } - currentNWWindowInternal.capturePageInternal(options, cb); + this.cWindow = currentNWWindowInternal.getCurrent(this.cWindow.id, {'populate': true}); + currentNWWindowInternal.capturePageInternal(this.cWindow.id, options, cb); }; function sendCommand(tabId, name, options) { diff --git a/src/resources/api_nw_window.js b/src/resources/api_nw_window.js index 9dbebd8e8e..7e50dadc26 100644 --- a/src/resources/api_nw_window.js +++ b/src/resources/api_nw_window.js @@ -403,7 +403,7 @@ apiBridge.registerCustomHook(function(bindingsAPI) { }; cb = cb.bind(undefined, options.datatype); } - currentNWWindowInternal.capturePageInternal(options, cb); + currentNWWindowInternal.capturePageInternal(0, options, cb); }; NWWindow.prototype.reload = function () { this.appWindow.contentWindow.location.reload();