Move handling of "preload" to web-view-attributes
This commit is contained in:
parent
6624fd9a1b
commit
64edede20d
2 changed files with 15 additions and 11 deletions
|
@ -170,6 +170,20 @@ class HttpReferrerAttribute extends WebViewAttribute
|
||||||
constructor: (webViewImpl) ->
|
constructor: (webViewImpl) ->
|
||||||
super webViewConstants.ATTRIBUTE_HTTPREFERRER, webViewImpl
|
super webViewConstants.ATTRIBUTE_HTTPREFERRER, webViewImpl
|
||||||
|
|
||||||
|
# Attribute that set preload script.
|
||||||
|
class PreloadAttribute extends WebViewAttribute
|
||||||
|
constructor: (webViewImpl) ->
|
||||||
|
super webViewConstants.ATTRIBUTE_PRELOAD, webViewImpl
|
||||||
|
|
||||||
|
getValue: ->
|
||||||
|
return '' unless @webViewImpl.webviewNode.hasAttribute @name
|
||||||
|
preload = resolveUrl @webViewImpl.webviewNode.getAttribute(@name)
|
||||||
|
protocol = preload.substr 0, 5
|
||||||
|
unless protocol in ['file:', 'asar:']
|
||||||
|
console.error webViewConstants.ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE
|
||||||
|
preload = ''
|
||||||
|
preload
|
||||||
|
|
||||||
# Sets up all of the webview attributes.
|
# Sets up all of the webview attributes.
|
||||||
WebViewImpl::setupWebViewAttributes = ->
|
WebViewImpl::setupWebViewAttributes = ->
|
||||||
@attributes = {}
|
@attributes = {}
|
||||||
|
@ -181,6 +195,7 @@ WebViewImpl::setupWebViewAttributes = ->
|
||||||
@attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER] = new HttpReferrerAttribute(this)
|
@attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER] = new HttpReferrerAttribute(this)
|
||||||
@attributes[webViewConstants.ATTRIBUTE_NODEINTEGRATION] = new BooleanAttribute(webViewConstants.ATTRIBUTE_NODEINTEGRATION, this)
|
@attributes[webViewConstants.ATTRIBUTE_NODEINTEGRATION] = new BooleanAttribute(webViewConstants.ATTRIBUTE_NODEINTEGRATION, this)
|
||||||
@attributes[webViewConstants.ATTRIBUTE_PLUGINS] = new BooleanAttribute(webViewConstants.ATTRIBUTE_PLUGINS, this)
|
@attributes[webViewConstants.ATTRIBUTE_PLUGINS] = new BooleanAttribute(webViewConstants.ATTRIBUTE_PLUGINS, this)
|
||||||
|
@attributes[webViewConstants.ATTRIBUTE_PRELOAD] = new PreloadAttribute(this)
|
||||||
|
|
||||||
autosizeAttributes = [
|
autosizeAttributes = [
|
||||||
webViewConstants.ATTRIBUTE_MAXHEIGHT
|
webViewConstants.ATTRIBUTE_MAXHEIGHT
|
||||||
|
|
|
@ -182,17 +182,6 @@ class WebViewImpl
|
||||||
userAgentOverride: @userAgentOverride
|
userAgentOverride: @userAgentOverride
|
||||||
for attributeName, attribute of @attributes
|
for attributeName, attribute of @attributes
|
||||||
params[attributeName] = attribute.getValue()
|
params[attributeName] = attribute.getValue()
|
||||||
if @webviewNode.hasAttribute webViewConstants.ATTRIBUTE_PRELOAD
|
|
||||||
preload = @webviewNode.getAttribute webViewConstants.ATTRIBUTE_PRELOAD
|
|
||||||
# Get the full path.
|
|
||||||
a = document.createElement 'a'
|
|
||||||
a.href = preload
|
|
||||||
params.preload = a.href
|
|
||||||
# Only support file: or asar: protocol.
|
|
||||||
protocol = params.preload.substr 0, 5
|
|
||||||
unless protocol in ['file:', 'asar:']
|
|
||||||
delete params.preload
|
|
||||||
console.error webViewConstants.ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE
|
|
||||||
params
|
params
|
||||||
|
|
||||||
attachWindow: (guestInstanceId) ->
|
attachWindow: (guestInstanceId) ->
|
||||||
|
|
Loading…
Add table
Reference in a new issue