Remove extra newlines around comments
This commit is contained in:
parent
990dc30e8d
commit
030d2a843c
40 changed files with 103 additions and 425 deletions
|
@ -9,9 +9,7 @@ getNextId = function() {
|
|||
return ++nextId;
|
||||
};
|
||||
|
||||
|
||||
// |options.type| can not be empty and has to include 'window' or 'screen'.
|
||||
|
||||
isValid = function(options) {
|
||||
return ((options != null ? options.types : void 0) != null) && Array.isArray(options.types);
|
||||
};
|
||||
|
|
|
@ -2,13 +2,10 @@ var common;
|
|||
|
||||
common = require('../../../../common/api/lib/exports/electron');
|
||||
|
||||
|
||||
// Import common modules.
|
||||
|
||||
common.defineProperties(exports);
|
||||
|
||||
Object.defineProperties(exports, {
|
||||
|
||||
// Renderer side modules, please sort with alphabet order.
|
||||
desktopCapturer: {
|
||||
enumerable: true,
|
||||
|
|
|
@ -7,9 +7,7 @@ binding = process.atomBinding('ipc');
|
|||
|
||||
v8Util = process.atomBinding('v8_util');
|
||||
|
||||
|
||||
// Created by init.coffee.
|
||||
|
||||
ipcRenderer = v8Util.getHiddenValue(global, 'ipc');
|
||||
|
||||
ipcRenderer.send = function() {
|
||||
|
|
|
@ -5,14 +5,10 @@ ref = require('electron'), ipcRenderer = ref.ipcRenderer, deprecate = ref.deprec
|
|||
|
||||
EventEmitter = require('events').EventEmitter;
|
||||
|
||||
|
||||
// This module is deprecated, we mirror everything from ipcRenderer.
|
||||
|
||||
deprecate.warn('ipc module', 'require("electron").ipcRenderer');
|
||||
|
||||
|
||||
// Routes events of ipcRenderer.
|
||||
|
||||
ipc = new EventEmitter;
|
||||
|
||||
ipcRenderer.emit = function() {
|
||||
|
@ -22,9 +18,7 @@ ipcRenderer.emit = function() {
|
|||
return EventEmitter.prototype.emit.apply(ipcRenderer, arguments);
|
||||
};
|
||||
|
||||
|
||||
// Deprecated.
|
||||
|
||||
for (method in ipcRenderer) {
|
||||
if (method.startsWith('send')) {
|
||||
ipc[method] = ipcRenderer[method];
|
||||
|
|
|
@ -7,9 +7,7 @@ v8Util = process.atomBinding('v8_util');
|
|||
|
||||
callbacksRegistry = new CallbacksRegistry;
|
||||
|
||||
|
||||
// Check for circular reference.
|
||||
|
||||
isCircular = function(field, visited) {
|
||||
if (typeof field === 'object') {
|
||||
if (indexOf.call(visited, field) >= 0) {
|
||||
|
@ -20,9 +18,7 @@ isCircular = function(field, visited) {
|
|||
return false;
|
||||
};
|
||||
|
||||
|
||||
// Convert the arguments object into an array of meta data.
|
||||
|
||||
wrapArgs = function(args, visited) {
|
||||
var valueToMeta;
|
||||
if (visited == null) {
|
||||
|
@ -90,9 +86,7 @@ wrapArgs = function(args, visited) {
|
|||
return Array.prototype.slice.call(args).map(valueToMeta);
|
||||
};
|
||||
|
||||
|
||||
// Convert meta data from browser into real value.
|
||||
|
||||
metaToValue = function(meta) {
|
||||
var RemoteFunction, el, i, j, len, len1, member, ref1, ref2, results, ret;
|
||||
switch (meta.type) {
|
||||
|
@ -121,7 +115,6 @@ metaToValue = function(meta) {
|
|||
break;
|
||||
default:
|
||||
if (meta.type === 'function') {
|
||||
|
||||
// A shadow class to represent the remote function object.
|
||||
ret = RemoteFunction = (function() {
|
||||
function RemoteFunction() {
|
||||
|
@ -163,10 +156,8 @@ metaToValue = function(meta) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Track delegate object's life time, and tell the browser to clean up
|
||||
when the object is GCed.
|
||||
*/
|
||||
// Track delegate object's life time, and tell the browser to clean up
|
||||
// when the object is GCed.
|
||||
v8Util.setDestructor(ret, function() {
|
||||
return ipcRenderer.send('ATOM_BROWSER_DEREFERENCE', meta.id);
|
||||
});
|
||||
|
@ -177,9 +168,7 @@ metaToValue = function(meta) {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
// Construct a plain object from the meta.
|
||||
|
||||
metaToPlainObject = function(meta) {
|
||||
var i, len, name, obj, ref1, ref2, value;
|
||||
obj = (function() {
|
||||
|
@ -198,13 +187,9 @@ metaToPlainObject = function(meta) {
|
|||
return obj;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Create a RemoteMemberFunction instance.
|
||||
This function's content should not be inlined into metaToValue, otherwise V8
|
||||
may consider it circular reference.
|
||||
*/
|
||||
|
||||
// Create a RemoteMemberFunction instance.
|
||||
// This function's content should not be inlined into metaToValue, otherwise V8
|
||||
// may consider it circular reference.
|
||||
createRemoteMemberFunction = function(metaId, name) {
|
||||
var RemoteMemberFunction;
|
||||
return RemoteMemberFunction = (function() {
|
||||
|
@ -228,13 +213,9 @@ createRemoteMemberFunction = function(metaId, name) {
|
|||
})();
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Create configuration for defineProperty.
|
||||
This function's content should not be inlined into metaToValue, otherwise V8
|
||||
may consider it circular reference.
|
||||
*/
|
||||
|
||||
// Create configuration for defineProperty.
|
||||
// This function's content should not be inlined into metaToValue, otherwise V8
|
||||
// may consider it circular reference.
|
||||
createRemoteMemberProperty = function(metaId, name) {
|
||||
return {
|
||||
enumerable: true,
|
||||
|
@ -253,28 +234,20 @@ createRemoteMemberProperty = function(metaId, name) {
|
|||
};
|
||||
};
|
||||
|
||||
|
||||
// Browser calls a callback in renderer.
|
||||
|
||||
ipcRenderer.on('ATOM_RENDERER_CALLBACK', function(event, id, args) {
|
||||
return callbacksRegistry.apply(id, metaToValue(args));
|
||||
});
|
||||
|
||||
|
||||
// A callback in browser is released.
|
||||
|
||||
ipcRenderer.on('ATOM_RENDERER_RELEASE_CALLBACK', function(event, id) {
|
||||
return callbacksRegistry.remove(id);
|
||||
});
|
||||
|
||||
|
||||
// List all built-in modules in browser process.
|
||||
|
||||
browserModules = require('../../../browser/api/lib/exports/electron');
|
||||
|
||||
|
||||
// And add a helper receiver for each one.
|
||||
|
||||
fn = function(name) {
|
||||
return Object.defineProperty(exports, name, {
|
||||
get: function() {
|
||||
|
@ -287,12 +260,9 @@ for (name in browserModules) {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
Get remote module.
|
||||
(Just like node's require, the modules are cached permanently, note that this
|
||||
is safe leak since the object is not expected to get freed in browser)
|
||||
*/
|
||||
|
||||
// Get remote module.
|
||||
// (Just like node's require, the modules are cached permanently, note that this
|
||||
// is safe leak since the object is not expected to get freed in browser)
|
||||
moduleCache = {};
|
||||
|
||||
exports.require = function(module) {
|
||||
|
@ -306,12 +276,10 @@ exports.require = function(module) {
|
|||
|
||||
|
||||
// Optimize require('electron').
|
||||
|
||||
moduleCache.electron = exports;
|
||||
|
||||
|
||||
// Alias to remote.require('electron').xxx.
|
||||
|
||||
builtinCache = {};
|
||||
|
||||
exports.getBuiltin = function(module) {
|
||||
|
@ -323,9 +291,7 @@ exports.getBuiltin = function(module) {
|
|||
return builtinCache[module] = metaToValue(meta);
|
||||
};
|
||||
|
||||
|
||||
// Get current BrowserWindow object.
|
||||
|
||||
windowCache = null;
|
||||
|
||||
exports.getCurrentWindow = function() {
|
||||
|
@ -337,9 +303,7 @@ exports.getCurrentWindow = function() {
|
|||
return windowCache = metaToValue(meta);
|
||||
};
|
||||
|
||||
|
||||
// Get current WebContents object.
|
||||
|
||||
webContentsCache = null;
|
||||
|
||||
exports.getCurrentWebContents = function() {
|
||||
|
@ -351,18 +315,14 @@ exports.getCurrentWebContents = function() {
|
|||
return webContentsCache = metaToValue(meta);
|
||||
};
|
||||
|
||||
|
||||
// Get a global object in browser.
|
||||
|
||||
exports.getGlobal = function(name) {
|
||||
var meta;
|
||||
meta = ipcRenderer.sendSync('ATOM_BROWSER_GLOBAL', name);
|
||||
return metaToValue(meta);
|
||||
};
|
||||
|
||||
|
||||
// Get the process object in browser.
|
||||
|
||||
processCache = null;
|
||||
|
||||
exports.__defineGetter__('process', function() {
|
||||
|
@ -372,9 +332,7 @@ exports.__defineGetter__('process', function() {
|
|||
return processCache;
|
||||
});
|
||||
|
||||
|
||||
// Create a funtion that will return the specifed value when called in browser.
|
||||
|
||||
exports.createFunctionWithReturnValue = function(returnValue) {
|
||||
var func;
|
||||
func = function() {
|
||||
|
@ -384,9 +342,7 @@ exports.createFunctionWithReturnValue = function(returnValue) {
|
|||
return func;
|
||||
};
|
||||
|
||||
|
||||
// Get the guest WebContents from guestInstanceId.
|
||||
|
||||
exports.getGuestWebContents = function(guestInstanceId) {
|
||||
var meta;
|
||||
meta = ipcRenderer.sendSync('ATOM_BROWSER_GUEST_WEB_CONTENTS', guestInstanceId);
|
||||
|
|
|
@ -11,21 +11,16 @@ url = require('url');
|
|||
Module = require('module');
|
||||
|
||||
|
||||
/*
|
||||
We modified the original process.argv to let node.js load the
|
||||
atom-renderer.js, we need to restore it here.
|
||||
*/
|
||||
|
||||
// We modified the original process.argv to let node.js load the
|
||||
// atom-renderer.js, we need to restore it here.
|
||||
process.argv.splice(1, 1);
|
||||
|
||||
|
||||
// Clear search paths.
|
||||
|
||||
require(path.resolve(__dirname, '..', '..', 'common', 'lib', 'reset-search-paths'));
|
||||
|
||||
|
||||
// Import common settings.
|
||||
|
||||
require(path.resolve(__dirname, '..', '..', 'common', 'lib', 'init'));
|
||||
|
||||
globalPaths = Module.globalPaths;
|
||||
|
@ -34,14 +29,10 @@ if (!process.env.ELECTRON_HIDE_INTERNAL_MODULES) {
|
|||
globalPaths.push(path.resolve(__dirname, '..', 'api', 'lib'));
|
||||
}
|
||||
|
||||
|
||||
// Expose public APIs.
|
||||
|
||||
globalPaths.push(path.resolve(__dirname, '..', 'api', 'lib', 'exports'));
|
||||
|
||||
|
||||
// The global variable will be used by ipc for event dispatching
|
||||
|
||||
v8Util = process.atomBinding('v8_util');
|
||||
|
||||
v8Util.setHiddenValue(global, 'ipc', new events.EventEmitter);
|
||||
|
@ -55,18 +46,15 @@ electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', (event, m
|
|||
});
|
||||
|
||||
// Process command line arguments.
|
||||
|
||||
nodeIntegration = 'false';
|
||||
|
||||
ref = process.argv;
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
arg = ref[i];
|
||||
if (arg.indexOf('--guest-instance-id=') === 0) {
|
||||
|
||||
// This is a guest web view.
|
||||
process.guestInstanceId = parseInt(arg.substr(arg.indexOf('=') + 1));
|
||||
} else if (arg.indexOf('--opener-id=') === 0) {
|
||||
|
||||
// This is a guest BrowserWindow.
|
||||
process.openerId = parseInt(arg.substr(arg.indexOf('=') + 1));
|
||||
} else if (arg.indexOf('--node-integration=') === 0) {
|
||||
|
@ -77,17 +65,14 @@ for (i = 0, len = ref.length; i < len; i++) {
|
|||
}
|
||||
|
||||
if (location.protocol === 'chrome-devtools:') {
|
||||
|
||||
// Override some inspector APIs.
|
||||
require('./inspector');
|
||||
nodeIntegration = 'true';
|
||||
} else if (location.protocol === 'chrome-extension:') {
|
||||
|
||||
// Add implementations of chrome API.
|
||||
require('./chrome-api');
|
||||
nodeIntegration = 'true';
|
||||
} else {
|
||||
|
||||
// Override default web functions.
|
||||
require('./override');
|
||||
|
||||
|
@ -99,7 +84,6 @@ if (location.protocol === 'chrome-devtools:') {
|
|||
}
|
||||
|
||||
if (nodeIntegration === 'true' || nodeIntegration === 'all' || nodeIntegration === 'except-iframe' || nodeIntegration === 'manual-enable-iframe') {
|
||||
|
||||
// Export node bindings to global.
|
||||
global.require = require;
|
||||
global.module = module;
|
||||
|
@ -135,7 +119,6 @@ if (nodeIntegration === 'true' || nodeIntegration === 'all' || nodeIntegration =
|
|||
return process.emit('exit');
|
||||
});
|
||||
} else {
|
||||
|
||||
// Delete Node's symbols after the Environment has been loaded.
|
||||
process.once('loaded', function() {
|
||||
delete global.process;
|
||||
|
@ -145,9 +128,7 @@ if (nodeIntegration === 'true' || nodeIntegration === 'all' || nodeIntegration =
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
// Load the script specfied by the "preload" attribute.
|
||||
|
||||
if (preloadScript) {
|
||||
try {
|
||||
require(preloadScript);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
var convertToMenuTemplate, createFileSelectorElement, createMenu, pathToHtml5FileObject, showFileChooserDialog;
|
||||
|
||||
window.onload = function() {
|
||||
|
||||
// Use menu API to show context menu.
|
||||
InspectorFrontendHost.showContextMenuAtPoint = createMenu;
|
||||
|
||||
|
|
|
@ -3,9 +3,7 @@ var BrowserWindowProxy, a, getHistoryOperation, ipcRenderer, ref, remote, resolv
|
|||
|
||||
ref = require('electron'), ipcRenderer = ref.ipcRenderer, remote = ref.remote;
|
||||
|
||||
|
||||
// Helper function to resolve relative url.
|
||||
|
||||
a = window.top.document.createElement('a');
|
||||
|
||||
resolveURL = function(url) {
|
||||
|
@ -13,9 +11,7 @@ resolveURL = function(url) {
|
|||
return a.href;
|
||||
};
|
||||
|
||||
|
||||
// Window object returned by "window.open".
|
||||
|
||||
BrowserWindowProxy = (function() {
|
||||
BrowserWindowProxy.proxies = {};
|
||||
|
||||
|
@ -69,16 +65,13 @@ BrowserWindowProxy = (function() {
|
|||
})();
|
||||
|
||||
if (process.guestInstanceId == null) {
|
||||
|
||||
// Override default window.close.
|
||||
window.close = function() {
|
||||
return remote.getCurrentWindow().close();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Make the browser window or guest view emit "new-window" event.
|
||||
|
||||
window.open = function(url, frameName, features) {
|
||||
var feature, guestId, i, ints, j, len, len1, name, options, ref1, ref2, value;
|
||||
if (frameName == null) {
|
||||
|
@ -133,9 +126,7 @@ window.open = function(url, frameName, features) {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
// Use the dialog API to implement alert().
|
||||
|
||||
window.alert = function(message, title) {
|
||||
var buttons;
|
||||
if (title == null) {
|
||||
|
@ -152,9 +143,7 @@ window.alert = function(message, title) {
|
|||
// Alert should always return undefined.
|
||||
};
|
||||
|
||||
|
||||
// And the confirm().
|
||||
|
||||
window.confirm = function(message, title) {
|
||||
var buttons, cancelId;
|
||||
if (title == null) {
|
||||
|
@ -170,9 +159,7 @@ window.confirm = function(message, title) {
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
// But we do not support prompt().
|
||||
|
||||
window.prompt = function() {
|
||||
throw new Error('prompt() is and will not be supported.');
|
||||
};
|
||||
|
@ -182,9 +169,7 @@ if (process.openerId != null) {
|
|||
}
|
||||
|
||||
ipcRenderer.on('ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', function(event, sourceId, message, sourceOrigin) {
|
||||
|
||||
// Manually dispatch event instead of using postMessage because we also need to
|
||||
|
||||
// set event.source.
|
||||
event = document.createEvent('Event');
|
||||
event.initEvent('message', false, false);
|
||||
|
@ -194,9 +179,7 @@ ipcRenderer.on('ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', function(event, sourceId,
|
|||
return window.dispatchEvent(event);
|
||||
});
|
||||
|
||||
|
||||
// Forward history operations to browser.
|
||||
|
||||
sendHistoryOperation = function() {
|
||||
var args;
|
||||
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
||||
|
@ -227,9 +210,7 @@ Object.defineProperty(window.history, 'length', {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
// Make document.hidden and document.visibilityState return the correct value.
|
||||
|
||||
Object.defineProperty(document, 'hidden', {
|
||||
get: function() {
|
||||
var currentWindow;
|
||||
|
|
|
@ -10,9 +10,7 @@ webViewConstants = require('./web-view-constants');
|
|||
|
||||
remote = require('electron').remote;
|
||||
|
||||
|
||||
// Helper function to resolve url set in attribute.
|
||||
|
||||
a = document.createElement('a');
|
||||
|
||||
resolveURL = function(url) {
|
||||
|
@ -20,12 +18,8 @@ resolveURL = function(url) {
|
|||
return a.href;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Attribute objects.
|
||||
Default implementation of a WebView attribute.
|
||||
*/
|
||||
|
||||
// Attribute objects.
|
||||
// Default implementation of a WebView attribute.
|
||||
WebViewAttribute = (function() {
|
||||
function WebViewAttribute(name, webViewImpl) {
|
||||
this.name = name;
|
||||
|
@ -35,32 +29,24 @@ WebViewAttribute = (function() {
|
|||
this.defineProperty();
|
||||
}
|
||||
|
||||
|
||||
// Retrieves and returns the attribute's value.
|
||||
|
||||
WebViewAttribute.prototype.getValue = function() {
|
||||
return this.webViewImpl.webviewNode.getAttribute(this.name) || this.value;
|
||||
};
|
||||
|
||||
|
||||
// Sets the attribute's value.
|
||||
|
||||
WebViewAttribute.prototype.setValue = function(value) {
|
||||
return this.webViewImpl.webviewNode.setAttribute(this.name, value || '');
|
||||
};
|
||||
|
||||
|
||||
// Changes the attribute's value without triggering its mutation handler.
|
||||
|
||||
WebViewAttribute.prototype.setValueIgnoreMutation = function(value) {
|
||||
this.ignoreMutation = true;
|
||||
this.setValue(value);
|
||||
return this.ignoreMutation = false;
|
||||
};
|
||||
|
||||
|
||||
// Defines this attribute as a property on the webview node.
|
||||
|
||||
WebViewAttribute.prototype.defineProperty = function() {
|
||||
return Object.defineProperty(this.webViewImpl.webviewNode, this.name, {
|
||||
get: (function(_this) {
|
||||
|
@ -77,18 +63,14 @@ WebViewAttribute = (function() {
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
// Called when the attribute's value changes.
|
||||
|
||||
WebViewAttribute.prototype.handleMutation = function() {};
|
||||
|
||||
return WebViewAttribute;
|
||||
|
||||
})();
|
||||
|
||||
|
||||
// An attribute that is treated as a Boolean.
|
||||
|
||||
BooleanAttribute = (function(superClass) {
|
||||
extend(BooleanAttribute, superClass);
|
||||
|
||||
|
@ -112,9 +94,7 @@ BooleanAttribute = (function(superClass) {
|
|||
|
||||
})(WebViewAttribute);
|
||||
|
||||
|
||||
// Attribute that specifies whether transparency is allowed in the webview.
|
||||
|
||||
AllowTransparencyAttribute = (function(superClass) {
|
||||
extend(AllowTransparencyAttribute, superClass);
|
||||
|
||||
|
@ -133,9 +113,7 @@ AllowTransparencyAttribute = (function(superClass) {
|
|||
|
||||
})(BooleanAttribute);
|
||||
|
||||
|
||||
// Attribute used to define the demension limits of autosizing.
|
||||
|
||||
AutosizeDimensionAttribute = (function(superClass) {
|
||||
extend(AutosizeDimensionAttribute, superClass);
|
||||
|
||||
|
@ -168,9 +146,7 @@ AutosizeDimensionAttribute = (function(superClass) {
|
|||
|
||||
})(WebViewAttribute);
|
||||
|
||||
|
||||
// Attribute that specifies whether the webview should be autosized.
|
||||
|
||||
AutosizeAttribute = (function(superClass) {
|
||||
extend(AutosizeAttribute, superClass);
|
||||
|
||||
|
@ -184,9 +160,7 @@ AutosizeAttribute = (function(superClass) {
|
|||
|
||||
})(BooleanAttribute);
|
||||
|
||||
|
||||
// Attribute representing the state of the storage partition.
|
||||
|
||||
PartitionAttribute = (function(superClass) {
|
||||
extend(PartitionAttribute, superClass);
|
||||
|
||||
|
@ -214,9 +188,7 @@ PartitionAttribute = (function(superClass) {
|
|||
|
||||
})(WebViewAttribute);
|
||||
|
||||
|
||||
// Attribute that handles the location and navigation of the webview.
|
||||
|
||||
SrcAttribute = (function(superClass) {
|
||||
extend(SrcAttribute, superClass);
|
||||
|
||||
|
@ -236,29 +208,23 @@ SrcAttribute = (function(superClass) {
|
|||
SrcAttribute.prototype.setValueIgnoreMutation = function(value) {
|
||||
WebViewAttribute.prototype.setValueIgnoreMutation.call(this, value);
|
||||
|
||||
/*
|
||||
takeRecords() is needed to clear queued up src mutations. Without it, it
|
||||
is possible for this change to get picked up asyncronously by src's
|
||||
mutation observer |observer|, and then get handled even though we do not
|
||||
want to handle this mutation.
|
||||
*/
|
||||
// takeRecords() is needed to clear queued up src mutations. Without it, it
|
||||
// is possible for this change to get picked up asyncronously by src's
|
||||
// mutation observer |observer|, and then get handled even though we do not
|
||||
// want to handle this mutation.
|
||||
return this.observer.takeRecords();
|
||||
};
|
||||
|
||||
SrcAttribute.prototype.handleMutation = function(oldValue, newValue) {
|
||||
|
||||
/*
|
||||
Once we have navigated, we don't allow clearing the src attribute.
|
||||
Once <webview> enters a navigated state, it cannot return to a
|
||||
placeholder state.
|
||||
*/
|
||||
// Once we have navigated, we don't allow clearing the src attribute.
|
||||
// Once <webview> enters a navigated state, it cannot return to a
|
||||
// placeholder state.
|
||||
if (!newValue && oldValue) {
|
||||
|
||||
/*
|
||||
src attribute changes normally initiate a navigation. We suppress
|
||||
the next src attribute handler call to avoid reloading the page
|
||||
on every guest-initiated navigation.
|
||||
*/
|
||||
// src attribute changes normally initiate a navigation. We suppress
|
||||
// the next src attribute handler call to avoid reloading the page
|
||||
// on every guest-initiated navigation.
|
||||
this.setValueIgnoreMutation(oldValue);
|
||||
return;
|
||||
}
|
||||
|
@ -266,13 +232,10 @@ SrcAttribute = (function(superClass) {
|
|||
};
|
||||
|
||||
|
||||
/*
|
||||
The purpose of this mutation observer is to catch assignment to the src
|
||||
attribute without any changes to its value. This is useful in the case
|
||||
where the webview guest has crashed and navigating to the same address
|
||||
spawns off a new process.
|
||||
*/
|
||||
|
||||
// The purpose of this mutation observer is to catch assignment to the src
|
||||
// attribute without any changes to its value. This is useful in the case
|
||||
// where the webview guest has crashed and navigating to the same address
|
||||
// spawns off a new process.
|
||||
SrcAttribute.prototype.setupMutationObserver = function() {
|
||||
var params;
|
||||
this.observer = new MutationObserver((function(_this) {
|
||||
|
@ -328,9 +291,7 @@ SrcAttribute = (function(superClass) {
|
|||
|
||||
})(WebViewAttribute);
|
||||
|
||||
|
||||
// Attribute specifies HTTP referrer.
|
||||
|
||||
HttpReferrerAttribute = (function(superClass) {
|
||||
extend(HttpReferrerAttribute, superClass);
|
||||
|
||||
|
@ -342,9 +303,7 @@ HttpReferrerAttribute = (function(superClass) {
|
|||
|
||||
})(WebViewAttribute);
|
||||
|
||||
|
||||
// Attribute specifies user agent
|
||||
|
||||
UserAgentAttribute = (function(superClass) {
|
||||
extend(UserAgentAttribute, superClass);
|
||||
|
||||
|
@ -356,9 +315,7 @@ UserAgentAttribute = (function(superClass) {
|
|||
|
||||
})(WebViewAttribute);
|
||||
|
||||
|
||||
// Attribute that set preload script.
|
||||
|
||||
PreloadAttribute = (function(superClass) {
|
||||
extend(PreloadAttribute, superClass);
|
||||
|
||||
|
@ -384,9 +341,7 @@ PreloadAttribute = (function(superClass) {
|
|||
|
||||
})(WebViewAttribute);
|
||||
|
||||
|
||||
// Sets up all of the webview attributes.
|
||||
|
||||
WebViewImpl.prototype.setupWebViewAttributes = function() {
|
||||
var attribute, autosizeAttributes, i, len, results;
|
||||
this.attributes = {};
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
module.exports = {
|
||||
|
||||
// Attributes.
|
||||
ATTRIBUTE_ALLOWTRANSPARENCY: 'allowtransparency',
|
||||
ATTRIBUTE_AUTOSIZE: 'autosize',
|
||||
|
|
|
@ -12,18 +12,14 @@ guestViewInternal = require('./guest-view-internal');
|
|||
|
||||
webViewConstants = require('./web-view-constants');
|
||||
|
||||
|
||||
// ID generator.
|
||||
|
||||
nextId = 0;
|
||||
|
||||
getNextId = function() {
|
||||
return ++nextId;
|
||||
};
|
||||
|
||||
|
||||
// Represents the internal state of the WebView node.
|
||||
|
||||
WebViewImpl = (function() {
|
||||
function WebViewImpl(webviewNode) {
|
||||
var shadowRoot;
|
||||
|
@ -50,32 +46,25 @@ WebViewImpl = (function() {
|
|||
}
|
||||
|
||||
WebViewImpl.prototype.createBrowserPluginNode = function() {
|
||||
|
||||
/*
|
||||
We create BrowserPlugin as a custom element in order to observe changes
|
||||
to attributes synchronously.
|
||||
*/
|
||||
// We create BrowserPlugin as a custom element in order to observe changes
|
||||
// to attributes synchronously.
|
||||
var browserPluginNode;
|
||||
browserPluginNode = new WebViewImpl.BrowserPlugin();
|
||||
v8Util.setHiddenValue(browserPluginNode, 'internal', this);
|
||||
return browserPluginNode;
|
||||
};
|
||||
|
||||
|
||||
// Resets some state upon reattaching <webview> element to the DOM.
|
||||
|
||||
WebViewImpl.prototype.reset = function() {
|
||||
// Unlisten the zoom-level-changed event.
|
||||
webFrame.removeListener('zoom-level-changed', this.onZoomLevelChanged);
|
||||
|
||||
/*
|
||||
If guestInstanceId is defined then the <webview> has navigated and has
|
||||
already picked up a partition ID. Thus, we need to reset the initialization
|
||||
state. However, it may be the case that beforeFirstNavigation is false BUT
|
||||
guestInstanceId has yet to be initialized. This means that we have not
|
||||
heard back from createGuest yet. We will not reset the flag in this case so
|
||||
that we don't end up allocating a second guest.
|
||||
*/
|
||||
// If guestInstanceId is defined then the <webview> has navigated and has
|
||||
// already picked up a partition ID. Thus, we need to reset the initialization
|
||||
// state. However, it may be the case that beforeFirstNavigation is false BUT
|
||||
// guestInstanceId has yet to be initialized. This means that we have not
|
||||
// heard back from createGuest yet. We will not reset the flag in this case so
|
||||
// that we don't end up allocating a second guest.
|
||||
if (this.guestInstanceId) {
|
||||
guestViewInternal.destroyGuest(this.guestInstanceId);
|
||||
this.webContents = null;
|
||||
|
@ -86,9 +75,7 @@ WebViewImpl = (function() {
|
|||
return this.internalInstanceId = 0;
|
||||
};
|
||||
|
||||
|
||||
// Sets the <webview>.request property.
|
||||
|
||||
WebViewImpl.prototype.setRequestPropertyOnWebViewNode = function(request) {
|
||||
return Object.defineProperty(this.webviewNode, 'request', {
|
||||
value: request,
|
||||
|
@ -99,12 +86,10 @@ WebViewImpl = (function() {
|
|||
WebViewImpl.prototype.setupFocusPropagation = function() {
|
||||
if (!this.webviewNode.hasAttribute('tabIndex')) {
|
||||
|
||||
/*
|
||||
<webview> needs a tabIndex in order to be focusable.
|
||||
TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute
|
||||
to allow <webview> to be focusable.
|
||||
See http://crbug.com/231664.
|
||||
*/
|
||||
// <webview> needs a tabIndex in order to be focusable.
|
||||
// TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute
|
||||
// to allow <webview> to be focusable.
|
||||
// See http://crbug.com/231664.
|
||||
this.webviewNode.setAttribute('tabIndex', -1);
|
||||
}
|
||||
this.webviewNode.addEventListener('focus', (function(_this) {
|
||||
|
@ -124,14 +109,11 @@ WebViewImpl = (function() {
|
|||
};
|
||||
|
||||
|
||||
/*
|
||||
This observer monitors mutations to attributes of the <webview> and
|
||||
updates the BrowserPlugin properties accordingly. In turn, updating
|
||||
a BrowserPlugin property will update the corresponding BrowserPlugin
|
||||
attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more
|
||||
details.
|
||||
*/
|
||||
|
||||
// This observer monitors mutations to attributes of the <webview> and
|
||||
// updates the BrowserPlugin properties accordingly. In turn, updating
|
||||
// a BrowserPlugin property will update the corresponding BrowserPlugin
|
||||
// attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more
|
||||
// details.
|
||||
WebViewImpl.prototype.handleWebviewAttributeMutation = function(attributeName, oldValue, newValue) {
|
||||
if (!this.attributes[attributeName] || this.attributes[attributeName].ignoreMutation) {
|
||||
return;
|
||||
|
@ -164,7 +146,6 @@ WebViewImpl = (function() {
|
|||
height = node.offsetHeight;
|
||||
|
||||
// Check the current bounds to make sure we do not resize <webview>
|
||||
|
||||
// outside of current constraints.
|
||||
maxWidth = this.attributes[webViewConstants.ATTRIBUTE_MAXWIDTH].getValue() | width;
|
||||
maxHeight = this.attributes[webViewConstants.ATTRIBUTE_MAXHEIGHT].getValue() | width;
|
||||
|
@ -176,16 +157,13 @@ WebViewImpl = (function() {
|
|||
node.style.width = newWidth + 'px';
|
||||
node.style.height = newHeight + 'px';
|
||||
|
||||
/*
|
||||
Only fire the DOM event if the size of the <webview> has actually
|
||||
changed.
|
||||
*/
|
||||
// Only fire the DOM event if the size of the <webview> has actually
|
||||
// changed.
|
||||
return this.dispatchEvent(webViewEvent);
|
||||
}
|
||||
};
|
||||
|
||||
WebViewImpl.prototype.onElementResize = function(newSize) {
|
||||
|
||||
// Dispatch the 'resize' event.
|
||||
var resizeEvent;
|
||||
resizeEvent = new Event('resize', {
|
||||
|
@ -213,12 +191,8 @@ WebViewImpl = (function() {
|
|||
return this.webviewNode.dispatchEvent(webViewEvent);
|
||||
};
|
||||
|
||||
|
||||
// Adds an 'on<event>' property on the webview, which can be used to set/unset
|
||||
|
||||
|
||||
// an event handler.
|
||||
|
||||
WebViewImpl.prototype.setupEventProperty = function(eventName) {
|
||||
var propertyName;
|
||||
propertyName = 'on' + eventName.toLowerCase();
|
||||
|
@ -243,20 +217,16 @@ WebViewImpl = (function() {
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
// Updates state upon loadcommit.
|
||||
|
||||
WebViewImpl.prototype.onLoadCommit = function(webViewEvent) {
|
||||
var newValue, oldValue;
|
||||
oldValue = this.webviewNode.getAttribute(webViewConstants.ATTRIBUTE_SRC);
|
||||
newValue = webViewEvent.url;
|
||||
if (webViewEvent.isMainFrame && (oldValue !== newValue)) {
|
||||
|
||||
/*
|
||||
Touching the src attribute triggers a navigation. To avoid
|
||||
triggering a page reload on every guest-initiated navigation,
|
||||
we do not handle this mutation.
|
||||
*/
|
||||
// Touching the src attribute triggers a navigation. To avoid
|
||||
// triggering a page reload on every guest-initiated navigation,
|
||||
// we do not handle this mutation.
|
||||
return this.attributes[webViewConstants.ATTRIBUTE_SRC].setValueIgnoreMutation(newValue);
|
||||
}
|
||||
};
|
||||
|
@ -278,13 +248,11 @@ WebViewImpl = (function() {
|
|||
params[attributeName] = attribute.getValue();
|
||||
}
|
||||
|
||||
/*
|
||||
When the WebView is not participating in layout (display:none)
|
||||
then getBoundingClientRect() would report a width and height of 0.
|
||||
However, in the case where the WebView has a fixed size we can
|
||||
use that value to initially size the guest so as to avoid a relayout of
|
||||
the on display:block.
|
||||
*/
|
||||
// When the WebView is not participating in layout (display:none)
|
||||
// then getBoundingClientRect() would report a width and height of 0.
|
||||
// However, in the case where the WebView has a fixed size we can
|
||||
// use that value to initially size the guest so as to avoid a relayout of
|
||||
// the on display:block.
|
||||
css = window.getComputedStyle(this.webviewNode, null);
|
||||
elementRect = this.webviewNode.getBoundingClientRect();
|
||||
params.elementWidth = parseInt(elementRect.width) || parseInt(css.getPropertyValue('width'));
|
||||
|
@ -305,9 +273,7 @@ WebViewImpl = (function() {
|
|||
|
||||
})();
|
||||
|
||||
|
||||
// Registers browser plugin <object> custom element.
|
||||
|
||||
registerBrowserPluginElement = function() {
|
||||
var proto;
|
||||
proto = Object.create(HTMLObjectElement.prototype);
|
||||
|
@ -329,7 +295,6 @@ registerBrowserPluginElement = function() {
|
|||
return internal.handleBrowserPluginAttributeMutation(name, oldValue, newValue);
|
||||
};
|
||||
proto.attachedCallback = function() {
|
||||
|
||||
// Load the plugin immediately.
|
||||
var unused;
|
||||
return unused = this.nonExistentAttribute;
|
||||
|
@ -344,9 +309,7 @@ registerBrowserPluginElement = function() {
|
|||
return delete proto.attributeChangedCallback;
|
||||
};
|
||||
|
||||
|
||||
// Registers <webview> custom element.
|
||||
|
||||
registerWebViewElement = function() {
|
||||
var createBlockHandler, createNonBlockHandler, i, j, len, len1, m, methods, nonblockMethods, proto;
|
||||
proto = Object.create(HTMLObjectElement.prototype);
|
||||
|
@ -385,7 +348,51 @@ registerWebViewElement = function() {
|
|||
};
|
||||
|
||||
// Public-facing API methods.
|
||||
methods = ['getURL', 'getTitle', 'isLoading', 'isWaitingForResponse', 'stop', 'reload', 'reloadIgnoringCache', 'canGoBack', 'canGoForward', 'canGoToOffset', 'clearHistory', 'goBack', 'goForward', 'goToIndex', 'goToOffset', 'isCrashed', 'setUserAgent', 'getUserAgent', 'openDevTools', 'closeDevTools', 'isDevToolsOpened', 'isDevToolsFocused', 'inspectElement', 'setAudioMuted', 'isAudioMuted', 'undo', 'redo', 'cut', 'copy', 'paste', 'pasteAndMatchStyle', 'delete', 'selectAll', 'unselect', 'replace', 'replaceMisspelling', 'findInPage', 'stopFindInPage', 'getId', 'downloadURL', 'inspectServiceWorker', 'print', 'printToPDF'];
|
||||
methods = [
|
||||
'getURL',
|
||||
'getTitle',
|
||||
'isLoading',
|
||||
'isWaitingForResponse',
|
||||
'stop',
|
||||
'reload',
|
||||
'reloadIgnoringCache',
|
||||
'canGoBack',
|
||||
'canGoForward',
|
||||
'canGoToOffset',
|
||||
'clearHistory',
|
||||
'goBack',
|
||||
'goForward',
|
||||
'goToIndex',
|
||||
'goToOffset',
|
||||
'isCrashed',
|
||||
'setUserAgent',
|
||||
'getUserAgent',
|
||||
'openDevTools',
|
||||
'closeDevTools',
|
||||
'isDevToolsOpened',
|
||||
'isDevToolsFocused',
|
||||
'inspectElement',
|
||||
'setAudioMuted',
|
||||
'isAudioMuted',
|
||||
'undo',
|
||||
'redo',
|
||||
'cut',
|
||||
'copy',
|
||||
'paste',
|
||||
'pasteAndMatchStyle',
|
||||
'delete',
|
||||
'selectAll',
|
||||
'unselect',
|
||||
'replace',
|
||||
'replaceMisspelling',
|
||||
'findInPage',
|
||||
'stopFindInPage',
|
||||
'getId',
|
||||
'downloadURL',
|
||||
'inspectServiceWorker',
|
||||
'print',
|
||||
'printToPDF'
|
||||
];
|
||||
nonblockMethods = [
|
||||
'executeJavaScript',
|
||||
'insertCSS',
|
||||
|
@ -429,10 +436,8 @@ registerWebViewElement = function() {
|
|||
prototype: proto
|
||||
});
|
||||
|
||||
/*
|
||||
Delete the callbacks so developers cannot call them and produce unexpected
|
||||
behavior.
|
||||
*/
|
||||
// Delete the callbacks so developers cannot call them and produce unexpected
|
||||
// behavior.
|
||||
delete proto.createdCallback;
|
||||
delete proto.attachedCallback;
|
||||
delete proto.detachedCallback;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue