From 7ce3571270cc09d12bf578078d1ebe5c8bdfc0e2 Mon Sep 17 00:00:00 2001 From: rreimann Date: Fri, 21 Apr 2017 15:14:56 +0200 Subject: [PATCH 01/36] Clarify requirements for resumable downloads --- docs/api/download-item.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/api/download-item.md b/docs/api/download-item.md index 6603b619aa..768d2f7bb2 100644 --- a/docs/api/download-item.md +++ b/docs/api/download-item.md @@ -100,6 +100,8 @@ Returns `Boolean` - Whether the download is paused. Resumes the download that has been paused. +**Note:** To enable resumable downloads in the narrow sense the server you are downloading from must support range requests and provide a Last-Modified as well as an ETag header value. Otherwise `resume()` will dismiss previously received bytes and restart the download from the beginning. + #### `downloadItem.canResume()` Resumes `Boolean` - Whether the download can resume. From 3c3e14b8201d9ff68d98902bda32738d8fb06a71 Mon Sep 17 00:00:00 2001 From: Hari Krishna Reddy Juturu Date: Fri, 21 Apr 2017 20:45:30 +0000 Subject: [PATCH 02/36] End session event on browser window --- atom/browser/api/atom_api_window.cc | 6 ++++++ atom/browser/api/atom_api_window.h | 1 + atom/browser/atom_browser_main_parts.cc | 12 ++++++++++++ atom/browser/native_window.cc | 7 +++++++ atom/browser/native_window.h | 1 + atom/browser/native_window_observer.h | 1 + atom/browser/native_window_views_win.cc | 5 +++++ docs/api/browser-window.md | 5 +++++ 8 files changed, 38 insertions(+) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 4cf2fee82f..1914899297 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -191,6 +191,12 @@ void Window::OnWindowClosed() { FROM_HERE, GetDestroyClosure()); } +#if defined(OS_WIN) +void Window::OnWindowEndSession() { + Emit("endsession"); +} +#endif + void Window::OnWindowBlur() { Emit("blur"); } diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 1388b63de7..9620a6bf4a 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -92,6 +92,7 @@ class Window : public mate::TrackableObject, const base::DictionaryValue& details) override; #if defined(OS_WIN) + void Window::OnWindowEndSession() override; void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) override; #endif diff --git a/atom/browser/atom_browser_main_parts.cc b/atom/browser/atom_browser_main_parts.cc index d3f8237d5e..577448e6d2 100644 --- a/atom/browser/atom_browser_main_parts.cc +++ b/atom/browser/atom_browser_main_parts.cc @@ -25,6 +25,10 @@ #include "device/geolocation/geolocation_provider.h" #include "v8/include/v8-debug.h" +#if defined(USE_AURA) +#include "ui/wm/core/wm_state.h" +#endif + #if defined(USE_X11) #include "chrome/browser/ui/libgtkui/gtk_util.h" #include "ui/events/devices/x11/touch_factory_x11.h" @@ -57,6 +61,10 @@ void Erase(T* container, typename T::iterator iter) { // static AtomBrowserMainParts* AtomBrowserMainParts::self_ = nullptr; +#if defined(USE_AURA) +wm::WMState* wm_state_ = nullptr; +#endif + AtomBrowserMainParts::AtomBrowserMainParts() : fake_browser_process_(new BrowserProcess), exit_code_(nullptr), @@ -159,6 +167,10 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() { node_bindings_->PrepareMessageLoop(); node_bindings_->RunMessageLoop(); +#if defined(USE_AURA) + wm_state_ = new wm::WMState; +#endif + #if defined(USE_X11) ui::TouchFactory::SetTouchDeviceListFromCommandLine(); #endif diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 93bfc76c51..f97e34378a 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -474,6 +474,13 @@ void NativeWindow::NotifyWindowClosed() { observer.OnWindowClosed(); } +#if defined(OS_WIN) +void NativeWindow::NotifyWindowEndSession() { + for (NativeWindowObserver& observer : observers_) + observer.OnWindowEndSession(); +} +#endif + void NativeWindow::NotifyWindowBlur() { for (NativeWindowObserver& observer : observers_) observer.OnWindowBlur(); diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 48b56e8b47..f8c75352ed 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -244,6 +244,7 @@ class NativeWindow : public base::SupportsUserData, const base::DictionaryValue& details); #if defined(OS_WIN) + void NotifyWindowEndSession(); void NotifyWindowMessage(UINT message, WPARAM w_param, LPARAM l_param); #endif diff --git a/atom/browser/native_window_observer.h b/atom/browser/native_window_observer.h index 191f1bcab4..ba99b5b0c8 100644 --- a/atom/browser/native_window_observer.h +++ b/atom/browser/native_window_observer.h @@ -78,6 +78,7 @@ class NativeWindowObserver { // Called when window message received #if defined(OS_WIN) + virtual void OnWindowEndSession() {} virtual void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {} #endif diff --git a/atom/browser/native_window_views_win.cc b/atom/browser/native_window_views_win.cc index 1b523e90b8..abda0d0b02 100644 --- a/atom/browser/native_window_views_win.cc +++ b/atom/browser/native_window_views_win.cc @@ -147,6 +147,11 @@ bool NativeWindowViews::PreHandleMSG( } return false; } + case WM_ENDSESSION: { + if (w_param) { + NotifyWindowEndSession(); + } + } default: return false; } diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index cd55ba0bbd..2147645b21 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -376,6 +376,11 @@ window.onbeforeunload = (e) => { Emitted when the window is closed. After you have received this event you should remove the reference to the window and avoid using it any more. +#### Event: 'endsession' _Windows_ + +Emitted when window session is going to end due to force shutdown or machine restart +or session log off. + #### Event: 'unresponsive' Emitted when the web page becomes unresponsive. From 9e8252c1f9ceed5acfc0f9a1fb711636ebc74c7d Mon Sep 17 00:00:00 2001 From: Hari Krishna Reddy Juturu Date: Fri, 21 Apr 2017 14:35:30 -0700 Subject: [PATCH 03/36] Remove wm_state change --- atom/browser/atom_browser_main_parts.cc | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/atom/browser/atom_browser_main_parts.cc b/atom/browser/atom_browser_main_parts.cc index 577448e6d2..d3f8237d5e 100644 --- a/atom/browser/atom_browser_main_parts.cc +++ b/atom/browser/atom_browser_main_parts.cc @@ -25,10 +25,6 @@ #include "device/geolocation/geolocation_provider.h" #include "v8/include/v8-debug.h" -#if defined(USE_AURA) -#include "ui/wm/core/wm_state.h" -#endif - #if defined(USE_X11) #include "chrome/browser/ui/libgtkui/gtk_util.h" #include "ui/events/devices/x11/touch_factory_x11.h" @@ -61,10 +57,6 @@ void Erase(T* container, typename T::iterator iter) { // static AtomBrowserMainParts* AtomBrowserMainParts::self_ = nullptr; -#if defined(USE_AURA) -wm::WMState* wm_state_ = nullptr; -#endif - AtomBrowserMainParts::AtomBrowserMainParts() : fake_browser_process_(new BrowserProcess), exit_code_(nullptr), @@ -167,10 +159,6 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() { node_bindings_->PrepareMessageLoop(); node_bindings_->RunMessageLoop(); -#if defined(USE_AURA) - wm_state_ = new wm::WMState; -#endif - #if defined(USE_X11) ui::TouchFactory::SetTouchDeviceListFromCommandLine(); #endif From 7ea6d01a8cac811375afb54f3dbace259e81bcba Mon Sep 17 00:00:00 2001 From: rreimann Date: Sat, 22 Apr 2017 18:15:07 +0200 Subject: [PATCH 04/36] Rephrase note for resume method --- docs/api/download-item.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/download-item.md b/docs/api/download-item.md index 768d2f7bb2..3aab513b8b 100644 --- a/docs/api/download-item.md +++ b/docs/api/download-item.md @@ -100,7 +100,7 @@ Returns `Boolean` - Whether the download is paused. Resumes the download that has been paused. -**Note:** To enable resumable downloads in the narrow sense the server you are downloading from must support range requests and provide a Last-Modified as well as an ETag header value. Otherwise `resume()` will dismiss previously received bytes and restart the download from the beginning. +**Note:** To enable resumable downloads the server you are downloading from must support range requests and provide a Last-Modified as well as an ETag header value. Otherwise `resume()` will dismiss previously received bytes and restart the download from the beginning. #### `downloadItem.canResume()` From 64cc53795189036d94524fb5313bf15004d421ef Mon Sep 17 00:00:00 2001 From: ArcticZeroo Date: Sat, 22 Apr 2017 23:11:04 -0400 Subject: [PATCH 05/36] Update faq.md Fix the most horrible typo of all time --- docs/faq.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/faq.md b/docs/faq.md index 0079d43f4e..abeac23f76 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -148,7 +148,7 @@ npm uninstall electron npm uninstall -g electron ``` -However if your are using the built-in module but still getting this error, it +However if you are using the built-in module but still getting this error, it is very likely you are using the module in the wrong process. For example `electron.app` can only be used in the main process, while `electron.webFrame` is only available in renderer processes. From 46823f944ca644c882dc086eb73dde3532b0c745 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Mon, 24 Apr 2017 09:57:34 +0200 Subject: [PATCH 06/36] Updated documentation on desktop notifications on Windows 7 --- docs/tutorial/desktop-environment-integration.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tutorial/desktop-environment-integration.md b/docs/tutorial/desktop-environment-integration.md index 412341fe70..1c82e360e8 100644 --- a/docs/tutorial/desktop-environment-integration.md +++ b/docs/tutorial/desktop-environment-integration.md @@ -36,8 +36,8 @@ are fine differences. * On Windows 8.1 and Windows 8, a shortcut to your app, with a [Application User Model ID][app-user-model-id], must be installed to the Start screen. Note, however, that it does not need to be pinned to the Start screen. -* On Windows 7, notifications are not supported. You can however send -"balloon notifications" using the [Tray API][tray-balloon]. +* On Windows 7, notifications work via a custom implemetation which visually +resembles the native one on newer systems. Furthermore, the maximum length for the notification body is 250 characters, with the Windows team recommending that notifications should be kept to 200 From 99985c0ed9f7d330a7ae191a47fbf536cee1a151 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 24 Apr 2017 08:49:59 -0700 Subject: [PATCH 07/36] Wrap header names in backticks --- docs/api/download-item.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/download-item.md b/docs/api/download-item.md index 3aab513b8b..51328758bf 100644 --- a/docs/api/download-item.md +++ b/docs/api/download-item.md @@ -100,7 +100,7 @@ Returns `Boolean` - Whether the download is paused. Resumes the download that has been paused. -**Note:** To enable resumable downloads the server you are downloading from must support range requests and provide a Last-Modified as well as an ETag header value. Otherwise `resume()` will dismiss previously received bytes and restart the download from the beginning. +**Note:** To enable resumable downloads the server you are downloading from must support range requests and provide a `Last-Modified` and `ETag` header value. Otherwise `resume()` will dismiss previously received bytes and restart the download from the beginning. #### `downloadItem.canResume()` From 13eeb1d17f698a27334fc77f3c2ca39f7d0dd762 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 24 Apr 2017 08:50:40 -0700 Subject: [PATCH 08/36] Minor wording tweaks --- docs/api/download-item.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/download-item.md b/docs/api/download-item.md index 51328758bf..c07bf98a86 100644 --- a/docs/api/download-item.md +++ b/docs/api/download-item.md @@ -100,7 +100,7 @@ Returns `Boolean` - Whether the download is paused. Resumes the download that has been paused. -**Note:** To enable resumable downloads the server you are downloading from must support range requests and provide a `Last-Modified` and `ETag` header value. Otherwise `resume()` will dismiss previously received bytes and restart the download from the beginning. +**Note:** To enable resumable downloads the server you are downloading from must support range requests and provide both `Last-Modified` and `ETag` header values. Otherwise `resume()` will dismiss previously received bytes and restart the download from the beginning. #### `downloadItem.canResume()` From 5f038cb3cb44500bc6e20102b23d8c4f049754bb Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 21 Apr 2017 10:12:19 -0700 Subject: [PATCH 09/36] Don't use document.write in default app --- default_app/index.html | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/default_app/index.html b/default_app/index.html index 3f29908a56..86100e19dd 100644 --- a/default_app/index.html +++ b/default_app/index.html @@ -146,7 +146,7 @@ - +
Docs @@ -162,25 +162,15 @@ Console (or Terminal):

- +

 
     

The path-to-your-app should be the path to your own Electron app.

-

You can read the - - guide in Electron's - +

You can read the quick start + guide in Electron's docs to learn how to write one.

@@ -214,6 +204,12 @@ }).unref(); return false; }; + + const version = process.versions.electron; + document.querySelector('.header-version').innerText = version; + document.querySelector('.command-example').innerText = command; + document.querySelector('.quick-start-link').href = `https://github.com/electron/electron/blob/v${version}/docs/tutorial/quick-start.md`; + document.querySelector('.docs-link').href = `https://github.com/electron/electron/tree/v${version}/docs#readme`; From a00d36fb071be1344396ee90279cb5bbadcf9e0e Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 21 Apr 2017 12:19:37 -0700 Subject: [PATCH 10/36] Add spec for alert/confirm toString errors --- spec/chromium-spec.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 6a5937bbce..4c5b85521a 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -880,4 +880,28 @@ describe('chromium feature', function () { }) }) }) + + describe('window.alert(message, title)', function () { + it('throws an exception when the arguments cannot be converted to strings', function () { + assert.throws(function () { + window.alert({toString: null}) + }, /Cannot convert object to primitive value/) + + assert.throws(function () { + window.alert('message', {toString: 3}) + }, /Cannot convert object to primitive value/) + }) + }) + + describe('window.confirm(message, title)', function () { + it('throws an exception when the arguments cannot be converted to strings', function () { + assert.throws(function () { + window.confirm({toString: null}, 'title') + }, /Cannot convert object to primitive value/) + + assert.throws(function () { + window.confirm('message', {toString: 3}) + }, /Cannot convert object to primitive value/) + }) + }) }) From c90fd4dc888662599a2f13d60eb39849db926abc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 21 Apr 2017 12:21:05 -0700 Subject: [PATCH 11/36] Convert message/title to strings in render process --- lib/renderer/window-setup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/renderer/window-setup.js b/lib/renderer/window-setup.js index 21f0741a22..d29133c88f 100644 --- a/lib/renderer/window-setup.js +++ b/lib/renderer/window-setup.js @@ -121,11 +121,11 @@ module.exports = (ipcRenderer, guestInstanceId, openerId, hiddenPage) => { } window.alert = function (message, title) { - ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_ALERT', message, title) + ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_ALERT', `${message}`, `${title}`) } window.confirm = function (message, title) { - return ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_CONFIRM', message, title) + return ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_CONFIRM', `${message}`, `${title}`) } // But we do not support prompt(). From 35a627fd603b4f340aa60eaaf397c0dad985b9b2 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 21 Apr 2017 12:29:46 -0700 Subject: [PATCH 12/36] Log all crashes during specs --- spec/static/main.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/spec/static/main.js b/spec/static/main.js index 033a0c5546..7e56da623b 100644 --- a/spec/static/main.js +++ b/spec/static/main.js @@ -2,20 +2,15 @@ process.throwDeprecation = true const electron = require('electron') -const app = electron.app -const crashReporter = electron.crashReporter -const ipcMain = electron.ipcMain -const dialog = electron.dialog -const BrowserWindow = electron.BrowserWindow -const protocol = electron.protocol -const webContents = electron.webContents -const v8 = require('v8') +const {app, BrowserWindow, crashReporter, dialog, ipcMain, protocol, webContents} = electron + +const {Coverage} = require('electabul') -const Coverage = require('electabul').Coverage const fs = require('fs') const path = require('path') const url = require('url') const util = require('util') +const v8 = require('v8') var argv = require('yargs') .boolean('ci') @@ -103,6 +98,12 @@ app.on('window-all-closed', function () { app.quit() }) +app.on('web-contents-created', (event, contents) => { + contents.on('crashed', (event, killed) => { + console.log(`webContents ${contents.id} crashed: ${contents.getURL()} (killed=${killed})`) + }) +}) + app.on('ready', function () { // Test if using protocol module would crash. electron.protocol.registerStringProtocol('test-if-crashes', function () {}) From 423dd4d57aebd8ba83b8a291d95618b71eb5b5e0 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 21 Apr 2017 15:12:08 -0700 Subject: [PATCH 13/36] Add spec for remote autoUpdater error event --- spec/api-auto-updater-spec.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/spec/api-auto-updater-spec.js b/spec/api-auto-updater-spec.js index 0716c2245d..3e2be93d13 100644 --- a/spec/api-auto-updater-spec.js +++ b/spec/api-auto-updater-spec.js @@ -1,6 +1,6 @@ const assert = require('assert') -const autoUpdater = require('electron').remote.autoUpdater -const ipcRenderer = require('electron').ipcRenderer +const {autoUpdater} = require('electron').remote +const {ipcRenderer} = require('electron') // Skip autoUpdater tests in MAS build. if (!process.mas) { @@ -64,5 +64,21 @@ if (!process.mas) { autoUpdater.quitAndInstall() }) }) + + describe('error event', function () { + it('serializes correctly over the remote module', function (done) { + autoUpdater.once('error', function (error) { + assert.equal(error instanceof Error, true) + assert.deepEqual(Object.getOwnPropertyNames(error), ['stack', 'message', 'name']) + done() + }) + + autoUpdater.setFeedURL('') + + if (process.platform === 'win32') { + autoUpdater.checkForUpdates() + } + }) + }) }) } From 13e4582697e8df68c8271ac6c813e81ec20722a1 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 21 Apr 2017 15:13:43 -0700 Subject: [PATCH 14/36] Emit autoUpdater error directly as Error object --- atom/browser/api/atom_api_auto_updater.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_auto_updater.cc b/atom/browser/api/atom_api_auto_updater.cc index ea3024191e..c23e488f64 100644 --- a/atom/browser/api/atom_api_auto_updater.cc +++ b/atom/browser/api/atom_api_auto_updater.cc @@ -7,6 +7,7 @@ #include "atom/browser/browser.h" #include "atom/browser/native_window.h" #include "atom/browser/window_list.h" +#include "atom/common/api/event_emitter_caller.h" #include "atom/common/native_mate_converters/callback.h" #include "atom/common/node_includes.h" #include "base/time/time.h" @@ -47,7 +48,9 @@ void AutoUpdater::OnError(const std::string& message) { v8::Locker locker(isolate()); v8::HandleScope handle_scope(isolate()); auto error = v8::Exception::Error(mate::StringToV8(isolate(), message)); - EmitCustomEvent( + mate::EmitEvent( + isolate(), + GetWrapper(), "error", error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked(), // Message is also emitted to keep compatibility with old code. From c2d4c93e12da6af51158bb31fd46f7f6ba261813 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 21 Apr 2017 16:50:19 -0700 Subject: [PATCH 15/36] Don't run error event on Linux --- spec/api-auto-updater-spec.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/api-auto-updater-spec.js b/spec/api-auto-updater-spec.js index 3e2be93d13..df77822e45 100644 --- a/spec/api-auto-updater-spec.js +++ b/spec/api-auto-updater-spec.js @@ -67,6 +67,10 @@ if (!process.mas) { describe('error event', function () { it('serializes correctly over the remote module', function (done) { + if (process.platform === 'linux') { + return done() + } + autoUpdater.once('error', function (error) { assert.equal(error instanceof Error, true) assert.deepEqual(Object.getOwnPropertyNames(error), ['stack', 'message', 'name']) From 9e70372c1fa408946bfbd8339ad65f583d6c9d73 Mon Sep 17 00:00:00 2001 From: Hari Krishna Reddy Juturu Date: Mon, 24 Apr 2017 10:16:11 -0700 Subject: [PATCH 16/36] change endsession event name to session-end --- atom/browser/api/atom_api_window.cc | 2 +- docs/api/browser-window.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 1914899297..95168efe9a 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -193,7 +193,7 @@ void Window::OnWindowClosed() { #if defined(OS_WIN) void Window::OnWindowEndSession() { - Emit("endsession"); + Emit("session-end"); } #endif diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 2147645b21..8fcc3f8213 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -376,7 +376,7 @@ window.onbeforeunload = (e) => { Emitted when the window is closed. After you have received this event you should remove the reference to the window and avoid using it any more. -#### Event: 'endsession' _Windows_ +#### Event: 'session-end' _Windows_ Emitted when window session is going to end due to force shutdown or machine restart or session log off. From 8a328268763d23377bfb06f573c5942077f26645 Mon Sep 17 00:00:00 2001 From: Hari Krishna Reddy Juturu Date: Mon, 24 Apr 2017 11:49:21 -0700 Subject: [PATCH 17/36] Removing #ifdef windows for endsession methods --- atom/browser/api/atom_api_window.h | 2 +- atom/browser/native_window.cc | 2 -- atom/browser/native_window.h | 2 +- atom/browser/native_window_observer.h | 4 +++- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 9620a6bf4a..75f0328ba6 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -63,6 +63,7 @@ class Window : public mate::TrackableObject, void WillCloseWindow(bool* prevent_default) override; void WillDestroyNativeObject() override; void OnWindowClosed() override; + void OnWindowEndSession() override; void OnWindowBlur() override; void OnWindowFocus() override; void OnWindowShow() override; @@ -92,7 +93,6 @@ class Window : public mate::TrackableObject, const base::DictionaryValue& details) override; #if defined(OS_WIN) - void Window::OnWindowEndSession() override; void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) override; #endif diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index f97e34378a..9e2c11aec4 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -474,12 +474,10 @@ void NativeWindow::NotifyWindowClosed() { observer.OnWindowClosed(); } -#if defined(OS_WIN) void NativeWindow::NotifyWindowEndSession() { for (NativeWindowObserver& observer : observers_) observer.OnWindowEndSession(); } -#endif void NativeWindow::NotifyWindowBlur() { for (NativeWindowObserver& observer : observers_) diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index f8c75352ed..d3f18d8fb9 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -218,6 +218,7 @@ class NativeWindow : public base::SupportsUserData, // Public API used by platform-dependent delegates and observers to send UI // related notifications. void NotifyWindowClosed(); + void NotifyWindowEndSession(); void NotifyWindowBlur(); void NotifyWindowFocus(); void NotifyWindowShow(); @@ -244,7 +245,6 @@ class NativeWindow : public base::SupportsUserData, const base::DictionaryValue& details); #if defined(OS_WIN) - void NotifyWindowEndSession(); void NotifyWindowMessage(UINT message, WPARAM w_param, LPARAM l_param); #endif diff --git a/atom/browser/native_window_observer.h b/atom/browser/native_window_observer.h index ba99b5b0c8..8c908dc823 100644 --- a/atom/browser/native_window_observer.h +++ b/atom/browser/native_window_observer.h @@ -40,6 +40,9 @@ class NativeWindowObserver { // Called when the window is closed. virtual void OnWindowClosed() {} + // Called when Windows sends WM_ENDSESSION message + virtual void OnWindowEndSession() {} + // Called when window loses focus. virtual void OnWindowBlur() {} @@ -78,7 +81,6 @@ class NativeWindowObserver { // Called when window message received #if defined(OS_WIN) - virtual void OnWindowEndSession() {} virtual void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {} #endif From 8458acff2600b2d2384c653b23ecaea74306be94 Mon Sep 17 00:00:00 2001 From: Hari Krishna Reddy Juturu Date: Mon, 24 Apr 2017 11:58:08 -0700 Subject: [PATCH 18/36] Removing #ifdef on endsession api --- atom/browser/api/atom_api_window.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 95168efe9a..72b8e33ef7 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -191,11 +191,9 @@ void Window::OnWindowClosed() { FROM_HERE, GetDestroyClosure()); } -#if defined(OS_WIN) void Window::OnWindowEndSession() { Emit("session-end"); } -#endif void Window::OnWindowBlur() { Emit("blur"); From ca5a8b6166e7ae4d9677d44c9fcc4d0804e322a4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 24 Apr 2017 11:54:05 -0700 Subject: [PATCH 19/36] Extract script tags to renderer.js file --- default_app/index.html | 44 +--------------------------------------- default_app/renderer.js | 45 +++++++++++++++++++++++++++++++++++++++++ filenames.gypi | 1 + 3 files changed, 47 insertions(+), 43 deletions(-) create mode 100644 default_app/renderer.js diff --git a/default_app/index.html b/default_app/index.html index 86100e19dd..41b5396360 100644 --- a/default_app/index.html +++ b/default_app/index.html @@ -113,24 +113,6 @@ - -
diff --git a/default_app/renderer.js b/default_app/renderer.js new file mode 100644 index 0000000000..6196195eab --- /dev/null +++ b/default_app/renderer.js @@ -0,0 +1,45 @@ +const {remote, shell} = require('electron') +const {execFile} = require('child_process') + +const {execPath} = remote.process + +document.onclick = function (e) { + e.preventDefault() + if (e.target.tagName === 'A') { + shell.openExternal(e.target.href) + } + return false +} + +document.ondragover = document.ondrop = function (e) { + e.preventDefault() + return false +} + +const holder = document.getElementById('holder') +holder.ondragover = function () { + this.className = 'hover' + return false +} + +holder.ondragleave = holder.ondragend = function () { + this.className = '' + return false +} + +holder.ondrop = function (e) { + this.className = '' + e.preventDefault() + + const file = e.dataTransfer.files[0] + execFile(execPath, [file.path], { + detached: true, stdio: 'ignore' + }).unref() + return false +} + +const version = process.versions.electron +document.querySelector('.header-version').innerText = version +document.querySelector('.command-example').innerText = `${execPath} path-to-your-app` +document.querySelector('.quick-start-link').href = `https://github.com/electron/electron/blob/v${version}/docs/tutorial/quick-start.md` +document.querySelector('.docs-link').href = `https://github.com/electron/electron/tree/v${version}/docs#readme` diff --git a/filenames.gypi b/filenames.gypi index 8f14b29883..6107ab956e 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -89,6 +89,7 @@ 'default_app/index.html', 'default_app/main.js', 'default_app/package.json', + 'default_app/renderer.js', ], 'lib_sources': [ 'atom/app/atom_content_client.cc', From 6ec74060b4dae3f44c7d73358071f44ad77a01b3 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 21 Apr 2017 10:57:22 -0700 Subject: [PATCH 20/36] Enable setting javascript and contextIsolation via window.open --- lib/browser/guest-window-manager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/browser/guest-window-manager.js b/lib/browser/guest-window-manager.js index e5bfa74123..e96fc12ac5 100644 --- a/lib/browser/guest-window-manager.js +++ b/lib/browser/guest-window-manager.js @@ -48,7 +48,7 @@ const mergeBrowserWindowOptions = function (embedder, options) { options.webPreferences.nodeIntegration = false } - // Enable context isolation on child window if enable on parent window + // Enable context isolation on child window if enabled on parent window if (embedder.getWebPreferences().contextIsolation === true) { options.webPreferences.contextIsolation = true } @@ -186,7 +186,7 @@ ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, url, frameName, const options = {} const ints = ['x', 'y', 'width', 'height', 'minWidth', 'maxWidth', 'minHeight', 'maxHeight', 'zoomFactor'] - const webPreferences = ['zoomFactor', 'nodeIntegration', 'preload'] + const webPreferences = ['zoomFactor', 'nodeIntegration', 'preload', 'javascript', 'contextIsolation'] const disposition = 'new-window' // Used to store additional features From cee050709017144e567c7b6ca1494e56ddc93ade Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 21 Apr 2017 10:58:47 -0700 Subject: [PATCH 21/36] Add failing spec for inheriting Javascript web preference --- spec/chromium-spec.js | 25 +++++++++++++++++++ spec/fixtures/pages/window-no-javascript.html | 12 +++++++++ 2 files changed, 37 insertions(+) create mode 100644 spec/fixtures/pages/window-no-javascript.html diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 4c5b85521a..977f25e103 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -229,6 +229,31 @@ describe('chromium feature', function () { b = window.open(windowUrl, '', 'nodeIntegration=no,show=no') }) + it('disables JavaScript when it is disabled on the parent window', function (done) { + var b + app.once('web-contents-created', (event, contents) => { + contents.once('did-finish-load', () => { + app.once('browser-window-created', (event, window) => { + const preferences = window.webContents.getWebPreferences() + assert.equal(preferences.javascript, false) + window.destroy() + b.close() + done() + }) + // Click link on page + contents.sendInputEvent({type: 'mouseDown', clickCount: 1, x: 1, y: 1}) + contents.sendInputEvent({type: 'mouseUp', clickCount: 1, x: 1, y: 1}) + }) + }) + + var windowUrl = require('url').format({ + pathname: `${fixtures}/pages/window-no-javascript.html`, + protocol: 'file', + slashes: true + }) + b = window.open(windowUrl, '', 'javascript=no,show=no') + }) + it('does not override child options', function (done) { var b, size size = { diff --git a/spec/fixtures/pages/window-no-javascript.html b/spec/fixtures/pages/window-no-javascript.html new file mode 100644 index 0000000000..9c38c9e0bb --- /dev/null +++ b/spec/fixtures/pages/window-no-javascript.html @@ -0,0 +1,12 @@ + + + + +CLICK + + From 3e2a1034af80c369e7c3d89dcbee9965eb5611a7 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 21 Apr 2017 10:59:33 -0700 Subject: [PATCH 22/36] Disable JavaScript on child when disabled on parent --- lib/browser/guest-window-manager.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/browser/guest-window-manager.js b/lib/browser/guest-window-manager.js index e96fc12ac5..8a8e9f46b8 100644 --- a/lib/browser/guest-window-manager.js +++ b/lib/browser/guest-window-manager.js @@ -53,6 +53,11 @@ const mergeBrowserWindowOptions = function (embedder, options) { options.webPreferences.contextIsolation = true } + // Disable JavaScript on child window if disabled on parent window + if (embedder.getWebPreferences().javascript === false) { + options.webPreferences.javascript = false + } + // Sets correct openerId here to give correct options to 'new-window' event handler options.webPreferences.openerId = embedder.id From 87db1b8aa718530a7b9ad050d145d21dee985cc4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 21 Apr 2017 11:00:31 -0700 Subject: [PATCH 23/36] Document other inherited web preferences --- docs/api/window-open.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/api/window-open.md b/docs/api/window-open.md index 56216f551a..41332aa6cf 100644 --- a/docs/api/window-open.md +++ b/docs/api/window-open.md @@ -30,6 +30,10 @@ has to be a field of `BrowserWindow`'s options. * Node integration will always be disabled in the opened `window` if it is disabled on the parent window. +* Context isolation will always be enabled in the opened `window` if it is + enabled on the parent window. +* JavaScript will always be disabled in the opened `window` if it is disabled on + the parent window. * Non-standard features (that are not handled by Chromium or Electron) given in `features` will be passed to any registered `webContent`'s `new-window` event handler in the `additionalFeatures` argument. From 3f88eb2f867f4340320b378a18605bd060fc97f5 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 24 Apr 2017 10:25:12 -0700 Subject: [PATCH 24/36] Add spec for chrome-devtools URL with no node integration --- spec/chromium-spec.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 977f25e103..9cce9fe280 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -229,6 +229,20 @@ describe('chromium feature', function () { b = window.open(windowUrl, '', 'nodeIntegration=no,show=no') }) + it('disables node integration when it is disabled on the parent window for chrome devtools URLs', function (done) { + var b + app.once('web-contents-created', (event, contents) => { + contents.once('did-finish-load', () => { + contents.executeJavaScript('typeof process').then((typeofProcessGlobal) => { + assert.equal(typeofProcessGlobal, 'undefined') + b.close() + done() + }).catch(done) + }) + }) + b = window.open('chrome-devtools://devtools/bundled/inspector.html', '', 'nodeIntegration=no,show=no') + }) + it('disables JavaScript when it is disabled on the parent window', function (done) { var b app.once('web-contents-created', (event, contents) => { From 05b6d91bf4c1e0ee65eeef70cd5d1bd1df125644 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 24 Apr 2017 10:25:40 -0700 Subject: [PATCH 25/36] Disable node integration in chrome-devtools: URLs --- lib/renderer/init.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/renderer/init.js b/lib/renderer/init.js index 0306463bc4..9b7ea9dabd 100644 --- a/lib/renderer/init.js +++ b/lib/renderer/init.js @@ -78,7 +78,7 @@ for (let arg of process.argv) { if (window.location.protocol === 'chrome-devtools:') { // Override some inspector APIs. require('./inspector') - nodeIntegration = 'true' + nodeIntegration = 'false' } else if (window.location.protocol === 'chrome-extension:') { // Add implementations of chrome API. require('./chrome-api').injectTo(window.location.hostname, isBackgroundPage, window) From 7e285711ca7d72a45bcec19039796354a9abbc6c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 25 Apr 2017 13:16:07 -0700 Subject: [PATCH 26/36] Add spec for window.open toString errors --- spec/chromium-spec.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 9cce9fe280..dd992dc0ae 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -361,6 +361,16 @@ describe('chromium feature', function () { }) b = window.open() }) + + it('throws an exception when the arguments cannot be converted to strings', function () { + assert.throws(function () { + window.open('', {toString: null}) + }, /Cannot convert object to primitive value/) + + assert.throws(function () { + window.open('', '', {toString: 3}) + }, /Cannot convert object to primitive value/) + }) }) describe('window.opener', function () { From 3894c1c625c568d77a539fb8ff60b39145e43e20 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 25 Apr 2017 13:16:28 -0700 Subject: [PATCH 27/36] Convert frameName/features to strings in render process --- lib/renderer/window-setup.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/renderer/window-setup.js b/lib/renderer/window-setup.js index d29133c88f..0bd43fb9a1 100644 --- a/lib/renderer/window-setup.js +++ b/lib/renderer/window-setup.js @@ -32,6 +32,10 @@ const resolveURL = function (url) { return a.href } +const toString = (value) => { + return value != null ? `${value}` : value +} + const windowProxies = {} const getOrCreateProxy = (ipcRenderer, guestId) => { @@ -112,7 +116,7 @@ module.exports = (ipcRenderer, guestInstanceId, openerId, hiddenPage) => { if (url != null && url !== '') { url = resolveURL(url) } - const guestId = ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, features) + const guestId = ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, toString(frameName), toString(features)) if (guestId != null) { return getOrCreateProxy(ipcRenderer, guestId) } else { @@ -121,11 +125,11 @@ module.exports = (ipcRenderer, guestInstanceId, openerId, hiddenPage) => { } window.alert = function (message, title) { - ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_ALERT', `${message}`, `${title}`) + ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_ALERT', toString(message), toString(title)) } window.confirm = function (message, title) { - return ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_CONFIRM', `${message}`, `${title}`) + return ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_CONFIRM', toString(message), toString(title)) } // But we do not support prompt(). From 246937a37209810779d43bd2c02c71174df29f28 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 25 Apr 2017 13:26:47 -0700 Subject: [PATCH 28/36] Convert targetOrigin to string in render process --- lib/renderer/window-setup.js | 5 ++++- spec/chromium-spec.js | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/renderer/window-setup.js b/lib/renderer/window-setup.js index 0bd43fb9a1..87a31f0624 100644 --- a/lib/renderer/window-setup.js +++ b/lib/renderer/window-setup.js @@ -32,6 +32,9 @@ const resolveURL = function (url) { return a.href } +// Use this method to ensure value expected as string in the main process +// are convertible to string in the renderer process. This ensures exceptions +// converting values to string are thrown in this process. const toString = (value) => { return value != null ? `${value}` : value } @@ -86,7 +89,7 @@ function BrowserWindowProxy (ipcRenderer, guestId) { } this.postMessage = (message, targetOrigin) => { - ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', guestId, message, targetOrigin, window.location.origin) + ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', guestId, message, toString(targetOrigin), window.location.origin) } this.eval = (...args) => { diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index dd992dc0ae..b0ae69af51 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -548,6 +548,14 @@ describe('chromium feature', function () { }) b = window.open('file://' + fixtures + '/pages/window-open-postMessage.html', '', 'show=no') }) + + it('throws an exception when the targetOrigin cannot be converted to a string', function () { + var b = window.open('') + assert.throws(function () { + b.postMessage('test', {toString: null}) + }, /Cannot convert object to primitive value/) + b.close() + }) }) describe('window.opener.postMessage', function () { From 2c48300daa487fdfab0c9786e3aa2ffe467d89c5 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 26 Apr 2017 09:09:42 -0700 Subject: [PATCH 29/36] Fix typos in comment --- lib/renderer/window-setup.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/renderer/window-setup.js b/lib/renderer/window-setup.js index 87a31f0624..5ccb6fec46 100644 --- a/lib/renderer/window-setup.js +++ b/lib/renderer/window-setup.js @@ -32,9 +32,9 @@ const resolveURL = function (url) { return a.href } -// Use this method to ensure value expected as string in the main process -// are convertible to string in the renderer process. This ensures exceptions -// converting values to string are thrown in this process. +// Use this method to ensure values expected as strings in the main process +// are convertible to strings in the renderer process. This ensures exceptions +// converting values to strings are thrown in this process. const toString = (value) => { return value != null ? `${value}` : value } From 9643b2a5c52e4d81b4d267920cd78f42027244a1 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 25 Apr 2017 13:52:56 -0700 Subject: [PATCH 30/36] Add specs for window.open frameName argument --- spec/chromium-spec.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index b0ae69af51..1b88d78e2a 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -371,6 +371,26 @@ describe('chromium feature', function () { window.open('', '', {toString: 3}) }, /Cannot convert object to primitive value/) }) + + it('sets the window title to the specified frameName', function (done) { + let b + app.once('browser-window-created', (event, createdWindow) => { + assert.equal(createdWindow.getTitle(), 'hello') + b.close() + done() + }) + b = window.open('', 'hello') + }) + + it('does not throw an exception when the frameName is a built-in object property', function (done) { + let b + app.once('browser-window-created', (event, createdWindow) => { + assert.equal(createdWindow.getTitle(), '__proto__') + b.close() + done() + }) + b = window.open('', '__proto__') + }) }) describe('window.opener', function () { From 91a1e5cdfef0e7efed130de5aff0d83af629c970 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 25 Apr 2017 13:53:29 -0700 Subject: [PATCH 31/36] Store frame to guests in map --- lib/browser/guest-window-manager.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/browser/guest-window-manager.js b/lib/browser/guest-window-manager.js index 8a8e9f46b8..33ec15a101 100644 --- a/lib/browser/guest-window-manager.js +++ b/lib/browser/guest-window-manager.js @@ -5,7 +5,7 @@ const {isSameOrigin} = process.atomBinding('v8_util') const parseFeaturesString = require('../common/parse-features-string') const hasProp = {}.hasOwnProperty -const frameToGuest = {} +const frameToGuest = new Map() // Copy attribute of |parent| to |child| if it is not defined in |child|. const mergeOptions = function (child, parent, visited) { @@ -92,10 +92,10 @@ const setupGuest = function (embedder, frameName, guest, options) { guest.once('closed', closedByUser) } if (frameName) { - frameToGuest[frameName] = guest + frameToGuest.set(frameName, guest) guest.frameName = frameName guest.once('closed', function () { - delete frameToGuest[frameName] + frameToGuest.delete(frameName) }) } return guestId @@ -103,7 +103,7 @@ const setupGuest = function (embedder, frameName, guest, options) { // Create a new guest created by |embedder| with |options|. const createGuest = function (embedder, url, frameName, options, postData) { - let guest = frameToGuest[frameName] + let guest = frameToGuest.get(frameName) if (frameName && (guest != null)) { guest.loadURL(url) return guest.webContents.id From 7726c7c6c4eb6cf037eef207958705578ad2271a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 25 Apr 2017 14:19:59 -0700 Subject: [PATCH 32/36] Add spec for webPreferences in features string --- spec/chromium-spec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 1b88d78e2a..700983bb5a 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -391,6 +391,14 @@ describe('chromium feature', function () { }) b = window.open('', '__proto__') }) + + it('does not throw an exception when the features include webPreferences', function () { + let b + assert.doesNotThrow(function () { + b = window.open('', '', 'webPreferences=') + }) + b.close() + }) }) describe('window.opener', function () { From 507f60e33e656248aeb40cc0d5fd8065a7dde5e4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 25 Apr 2017 14:20:39 -0700 Subject: [PATCH 33/36] Don't allow webPreferences to be overrideden in features string --- lib/browser/guest-window-manager.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/browser/guest-window-manager.js b/lib/browser/guest-window-manager.js index 33ec15a101..e668a3114a 100644 --- a/lib/browser/guest-window-manager.js +++ b/lib/browser/guest-window-manager.js @@ -202,6 +202,10 @@ ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, url, frameName, if (value === undefined) { additionalFeatures.push(key) } else { + // Don't allow webPreferences to be set since it must be an object + // that cannot be directly overridden + if (key === 'webPreferences') return + if (webPreferences.includes(key)) { if (options.webPreferences == null) { options.webPreferences = {} From 775753c3d738b50c3d02c18f0e48cd55ee258385 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 25 Apr 2017 14:48:01 -0700 Subject: [PATCH 34/36] Add spec for invalid window.history.go offset --- spec/chromium-spec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 700983bb5a..d5d1b3f478 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -989,4 +989,12 @@ describe('chromium feature', function () { }, /Cannot convert object to primitive value/) }) }) + + describe('window.history.go(offset)', function () { + it('throws an exception when the argumnet cannot be converted to a string', function () { + assert.throws(function () { + window.history.go({toString: null}) + }, /Cannot convert object to primitive value/) + }) + }) }) From 95ef422ab4c350c089ecc4f8fbce24b97c958f19 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 25 Apr 2017 14:49:14 -0700 Subject: [PATCH 35/36] Coerce offset to number in renderer process --- lib/renderer/window-setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/renderer/window-setup.js b/lib/renderer/window-setup.js index 5ccb6fec46..99f7aef542 100644 --- a/lib/renderer/window-setup.js +++ b/lib/renderer/window-setup.js @@ -164,7 +164,7 @@ module.exports = (ipcRenderer, guestInstanceId, openerId, hiddenPage) => { } window.history.go = function (offset) { - sendHistoryOperation(ipcRenderer, 'goToOffset', offset) + sendHistoryOperation(ipcRenderer, 'goToOffset', +offset) } defineProperty(window.history, 'length', { From f6bbcc6efa198e1215bc99fdb6919aa507adbeb6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 26 Apr 2017 09:06:10 -0700 Subject: [PATCH 36/36] Fix typos --- docs/api/menu-item.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/menu-item.md b/docs/api/menu-item.md index 494bdb74f1..a7486f3003 100644 --- a/docs/api/menu-item.md +++ b/docs/api/menu-item.md @@ -70,7 +70,7 @@ The `role` property can have following values: * `editMenu` - Whole default "Edit" menu (Undo, Copy, etc.) * `windowMenu` - Whole default "Window" menu (Minimize, Close, etc.) -The following additional roles are avaiable on macOS: +The following additional roles are available on macOS: * `about` - Map to the `orderFrontStandardAboutPanel` action * `hide` - Map to the `hide` action @@ -120,4 +120,4 @@ A String representing the menu items visible label #### `menuItem.click` -A Function that is fired when the MenuItem recieves a click event +A Function that is fired when the MenuItem receives a click event