Updated required code to handle missing additional features for popup windows
This commit is contained in:
parent
ef88a06f08
commit
c811188e22
9 changed files with 35 additions and 17 deletions
|
@ -525,6 +525,7 @@ void App::OnLogin(LoginHandler* login_handler,
|
|||
void App::OnCreateWindow(const GURL& target_url,
|
||||
const std::string& frame_name,
|
||||
WindowOpenDisposition disposition,
|
||||
const std::vector<base::string16>& features,
|
||||
int render_process_id,
|
||||
int render_frame_id) {
|
||||
v8::Locker locker(isolate());
|
||||
|
@ -535,7 +536,10 @@ void App::OnCreateWindow(const GURL& target_url,
|
|||
content::WebContents::FromRenderFrameHost(rfh);
|
||||
if (web_contents) {
|
||||
auto api_web_contents = WebContents::CreateFrom(isolate(), web_contents);
|
||||
api_web_contents->OnCreateWindow(target_url, frame_name, disposition);
|
||||
api_web_contents->OnCreateWindow(target_url,
|
||||
frame_name,
|
||||
disposition,
|
||||
features);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#define ATOM_BROWSER_API_ATOM_API_APP_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/api/event_emitter.h"
|
||||
#include "atom/browser/atom_browser_client.h"
|
||||
|
@ -50,6 +51,7 @@ class App : public AtomBrowserClient::Delegate,
|
|||
void OnCreateWindow(const GURL& target_url,
|
||||
const std::string& frame_name,
|
||||
WindowOpenDisposition disposition,
|
||||
const std::vector<base::string16>& features,
|
||||
int render_process_id,
|
||||
int render_frame_id);
|
||||
|
||||
|
|
|
@ -416,11 +416,12 @@ bool WebContents::AddMessageToConsole(content::WebContents* source,
|
|||
|
||||
void WebContents::OnCreateWindow(const GURL& target_url,
|
||||
const std::string& frame_name,
|
||||
WindowOpenDisposition disposition) {
|
||||
WindowOpenDisposition disposition,
|
||||
const std::vector<base::string16>& features) {
|
||||
if (type_ == BROWSER_WINDOW || type_ == OFF_SCREEN)
|
||||
Emit("-new-window", target_url, frame_name, disposition);
|
||||
Emit("-new-window", target_url, frame_name, disposition, features);
|
||||
else
|
||||
Emit("new-window", target_url, frame_name, disposition);
|
||||
Emit("new-window", target_url, frame_name, disposition, features);
|
||||
}
|
||||
|
||||
void WebContents::WebContentsCreated(content::WebContents* source_contents,
|
||||
|
|
|
@ -178,7 +178,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
// Create window with the given disposition.
|
||||
void OnCreateWindow(const GURL& target_url,
|
||||
const std::string& frame_name,
|
||||
WindowOpenDisposition disposition);
|
||||
WindowOpenDisposition disposition,
|
||||
const std::vector<base::string16>& features);
|
||||
|
||||
// Returns the web preferences of current WebContents.
|
||||
v8::Local<v8::Value> GetWebPreferences(v8::Isolate* isolate);
|
||||
|
|
|
@ -318,6 +318,7 @@ bool AtomBrowserClient::CanCreateWindow(
|
|||
const content::Referrer& referrer,
|
||||
WindowOpenDisposition disposition,
|
||||
const blink::WebWindowFeatures& features,
|
||||
const std::vector<base::string16>& additional_features,
|
||||
bool user_gesture,
|
||||
bool opener_suppressed,
|
||||
content::ResourceContext* context,
|
||||
|
@ -339,6 +340,7 @@ bool AtomBrowserClient::CanCreateWindow(
|
|||
target_url,
|
||||
frame_name,
|
||||
disposition,
|
||||
additional_features,
|
||||
render_process_id,
|
||||
opener_render_frame_id));
|
||||
}
|
||||
|
|
|
@ -88,6 +88,7 @@ class AtomBrowserClient : public brightray::BrowserClient,
|
|||
const content::Referrer& referrer,
|
||||
WindowOpenDisposition disposition,
|
||||
const blink::WebWindowFeatures& features,
|
||||
const std::vector<base::string16>& additional_features,
|
||||
bool user_gesture,
|
||||
bool opener_suppressed,
|
||||
content::ResourceContext* context,
|
||||
|
|
|
@ -18,13 +18,13 @@ BrowserWindow.prototype._init = function () {
|
|||
}
|
||||
|
||||
// Make new windows requested by links behave like "window.open"
|
||||
this.webContents.on('-new-window', (event, url, frameName, disposition) => {
|
||||
this.webContents.on('-new-window', (event, url, frameName, disposition, additionalFeatures) => {
|
||||
const options = {
|
||||
show: true,
|
||||
width: 800,
|
||||
height: 600
|
||||
}
|
||||
ipcMain.emit('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', event, url, frameName, disposition, options)
|
||||
ipcMain.emit('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', event, url, frameName, disposition, options, additionalFeatures)
|
||||
})
|
||||
|
||||
this.webContents.on('-web-contents-created', (event, webContents, url,
|
||||
|
|
|
@ -135,9 +135,9 @@ const getGuestWindow = function (guestId) {
|
|||
}
|
||||
|
||||
// Routed window.open messages.
|
||||
ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', function (event, url, frameName, disposition, options) {
|
||||
ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', function (event, url, frameName, disposition, options, additionalFeatures) {
|
||||
options = mergeBrowserWindowOptions(event.sender, options)
|
||||
event.sender.emit('new-window', event, url, frameName, disposition, options)
|
||||
event.sender.emit('new-window', event, url, frameName, disposition, options, additionalFeatures)
|
||||
if ((event.sender.isGuest() && !event.sender.allowPopups) || event.defaultPrevented) {
|
||||
event.returnValue = null
|
||||
} else {
|
||||
|
|
|
@ -88,7 +88,7 @@ if (process.guestInstanceId == null) {
|
|||
|
||||
// Make the browser window or guest view emit "new-window" event.
|
||||
window.open = function (url, frameName, features) {
|
||||
var feature, guestId, i, j, len, len1, name, options, ref1, ref2, value
|
||||
var feature, guestId, i, j, len, len1, name, options, ref1, ref2, value, additionalFeatures
|
||||
if (frameName == null) {
|
||||
frameName = ''
|
||||
}
|
||||
|
@ -101,6 +101,9 @@ window.open = function (url, frameName, features) {
|
|||
const webPreferences = ['zoomFactor', 'nodeIntegration', 'preload']
|
||||
const disposition = 'new-window'
|
||||
|
||||
// Used to store additional features
|
||||
additionalFeatures = []
|
||||
|
||||
// Make sure to get rid of excessive whitespace in the property name
|
||||
ref1 = features.split(/,\s*/)
|
||||
for (i = 0, len = ref1.length; i < len; i++) {
|
||||
|
@ -109,6 +112,9 @@ window.open = function (url, frameName, features) {
|
|||
name = ref2[0]
|
||||
value = ref2[1]
|
||||
value = value === 'yes' || value === '1' ? true : value === 'no' || value === '0' ? false : value
|
||||
if (value === undefined) {
|
||||
additionalFeatures.push(feature)
|
||||
} else {
|
||||
if (webPreferences.includes(name)) {
|
||||
if (options.webPreferences == null) {
|
||||
options.webPreferences = {}
|
||||
|
@ -118,6 +124,7 @@ window.open = function (url, frameName, features) {
|
|||
options[name] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
if (options.left) {
|
||||
if (options.x == null) {
|
||||
options.x = options.left
|
||||
|
@ -150,7 +157,7 @@ window.open = function (url, frameName, features) {
|
|||
options[name] = parseInt(options[name], 10)
|
||||
}
|
||||
}
|
||||
guestId = ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, disposition, options)
|
||||
guestId = ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, disposition, options, additionalFeatures)
|
||||
if (guestId) {
|
||||
return BrowserWindowProxy.getOrCreate(guestId)
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue