Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: warn memory leak when using nativeWindowOpen with nodeIntegration (2-0-x) #15207

Merged
merged 2 commits into from Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions atom/browser/api/atom_api_web_contents.cc
Expand Up @@ -310,7 +310,8 @@ WebContents::WebContents(v8::Isolate* isolate,
type_(type),
request_id_(0),
background_throttling_(true),
enable_devtools_(true) {
enable_devtools_(true),
is_dom_ready_(false) {
const mate::Dictionary options = mate::Dictionary::CreateEmpty(isolate);
if (type == REMOTE) {
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
Expand Down Expand Up @@ -799,8 +800,10 @@ void WebContents::DidChangeThemeColor(SkColor theme_color) {

void WebContents::DocumentLoadedInFrame(
content::RenderFrameHost* render_frame_host) {
if (!render_frame_host->GetParent())
if (!render_frame_host->GetParent()) {
is_dom_ready_ = true;
Emit("dom-ready");
}
}

void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
Expand All @@ -822,6 +825,7 @@ void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host,
}

void WebContents::DidStartLoading() {
is_dom_ready_ = false;
Emit("did-start-loading");
}

Expand Down Expand Up @@ -1343,6 +1347,10 @@ bool WebContents::IsAudioMuted() {
return web_contents()->IsAudioMuted();
}

bool WebContents::IsDOMReady() const {
return is_dom_ready_;
}

void WebContents::Print(mate::Arguments* args) {
PrintSettings settings = { false, false, base::string16() };
if (args->Length() >= 1 && !args->GetNext(&settings)) {
Expand Down Expand Up @@ -1934,6 +1942,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
&WebContents::SetIgnoreMenuShortcuts)
.SetMethod("setAudioMuted", &WebContents::SetAudioMuted)
.SetMethod("isAudioMuted", &WebContents::IsAudioMuted)
.SetMethod("isDomReady", &WebContents::IsDOMReady)
.SetMethod("undo", &WebContents::Undo)
.SetMethod("redo", &WebContents::Redo)
.SetMethod("cut", &WebContents::Cut)
Expand Down
4 changes: 4 additions & 0 deletions atom/browser/api/atom_api_web_contents.h
Expand Up @@ -125,6 +125,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
void SetIgnoreMenuShortcuts(bool ignore);
void SetAudioMuted(bool muted);
bool IsAudioMuted();
bool IsDOMReady() const;
void Print(mate::Arguments* args);
std::vector<printing::PrinterBasicInfo> GetPrinterList();
void SetEmbedder(const WebContents* embedder);
Expand Down Expand Up @@ -430,6 +431,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
// Whether to enable devtools.
bool enable_devtools_;

// Whether page's document is ready.
bool is_dom_ready_;

DISALLOW_COPY_AND_ASSIGN(WebContents);
};

Expand Down
15 changes: 15 additions & 0 deletions lib/browser/api/browser-window.js
Expand Up @@ -49,6 +49,21 @@ BrowserWindow.prototype._init = function () {
return
}

if (webContents.getLastWebPreferences().nodeIntegration === true) {
const message =
'Enabling Node.js integration in child windows opened with the ' +
'"nativeWindowOpen" option will cause memory leaks, please turn off ' +
'the "nodeIntegration" option.\\n' +
'See https://github.com/electron/electron/pull/15076 for more.'
// console is only available after DOM is created.
const printWarning = () => this.webContents.executeJavaScript(`console.warn('${message}')`)
if (this.webContents.isDomReady()) {
printWarning()
} else {
this.webContents.once('dom-ready', printWarning)
}
}

let {url, frameName} = urlFrameName
v8Util.deleteHiddenValue(webContents, 'url-framename')
const options = {
Expand Down