Automated the definitions of webview attributes as properties on the webview node
Imported from:
aef58f49f6
%5E%21/
This commit is contained in:
parent
2c27b953b5
commit
b6b8b936f2
2 changed files with 10 additions and 30 deletions
|
@ -15,16 +15,22 @@ class WebViewAttribute
|
||||||
# Sets the attribute's value.
|
# Sets the attribute's value.
|
||||||
setValue: (value) -> @webViewImpl.webviewNode.setAttribute(@name, value || '')
|
setValue: (value) -> @webViewImpl.webviewNode.setAttribute(@name, value || '')
|
||||||
|
|
||||||
|
# Defines this attribute as a property on the webview node.
|
||||||
|
define: ->
|
||||||
|
Object.defineProperty @webViewImpl.webviewNode, @name,
|
||||||
|
get: => @getValue()
|
||||||
|
set: (value) => @setValue value
|
||||||
|
enumerable: true
|
||||||
|
|
||||||
# Called when the attribute's value changes.
|
# Called when the attribute's value changes.
|
||||||
handleMutation: ->
|
handleMutation: ->
|
||||||
|
|
||||||
# Attribute specifying whether transparency is allowed in the webview.
|
# An attribute that is treated as a Boolean.
|
||||||
class BooleanAttribute extends WebViewAttribute
|
class BooleanAttribute extends WebViewAttribute
|
||||||
constructor: (name, webViewImpl) ->
|
constructor: (name, webViewImpl) ->
|
||||||
super name, webViewImpl
|
super name, webViewImpl
|
||||||
|
|
||||||
getValue: ->
|
getValue: ->
|
||||||
# This attribute is treated as a boolean, and is retrieved as such.
|
|
||||||
@webViewImpl.webviewNode.hasAttribute @name
|
@webViewImpl.webviewNode.hasAttribute @name
|
||||||
|
|
||||||
setValue: (value) ->
|
setValue: (value) ->
|
||||||
|
|
|
@ -99,20 +99,9 @@ class WebView
|
||||||
validateExecuteCodeCall: ->
|
validateExecuteCodeCall: ->
|
||||||
throw new Error(webViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT) unless @guestInstanceId
|
throw new Error(webViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT) unless @guestInstanceId
|
||||||
|
|
||||||
setupAutoSizeProperties: ->
|
|
||||||
for attributeName in AUTO_SIZE_ATTRIBUTES
|
|
||||||
Object.defineProperty @webviewNode, attributeName,
|
|
||||||
get: => @attributes[attributeName].getValue()
|
|
||||||
set: (value) => @attributes[attributeName].setValue value
|
|
||||||
enumerable: true
|
|
||||||
|
|
||||||
setupWebviewNodeProperties: ->
|
setupWebviewNodeProperties: ->
|
||||||
@setupAutoSizeProperties()
|
for attributeName of @attributes
|
||||||
|
@attributes[attributeName].define()
|
||||||
Object.defineProperty @webviewNode, webViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY,
|
|
||||||
get: => @attributes[webViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY].getValue()
|
|
||||||
set: (value) => @attributes[webViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY].setValue value
|
|
||||||
enumerable: true
|
|
||||||
|
|
||||||
# We cannot use {writable: true} property descriptor because we want a
|
# We cannot use {writable: true} property descriptor because we want a
|
||||||
# dynamic getter value.
|
# dynamic getter value.
|
||||||
|
@ -123,21 +112,6 @@ class WebView
|
||||||
# No setter.
|
# No setter.
|
||||||
enumerable: true
|
enumerable: true
|
||||||
|
|
||||||
Object.defineProperty @webviewNode, webViewConstants.ATTRIBUTE_PARTITION,
|
|
||||||
get: => @attributes[webViewConstants.ATTRIBUTE_PARTITION].getValue()
|
|
||||||
set: (value) => @attributes[webViewConstants.ATTRIBUTE_PARTITION].setValue value
|
|
||||||
enumerable: true
|
|
||||||
|
|
||||||
Object.defineProperty @webviewNode, webViewConstants.ATTRIBUTE_SRC,
|
|
||||||
get: => @attributes[webViewConstants.ATTRIBUTE_SRC].getValue()
|
|
||||||
set: (value) => @attributes[webViewConstants.ATTRIBUTE_SRC].setValue value
|
|
||||||
enumerable: true
|
|
||||||
|
|
||||||
Object.defineProperty @webviewNode, webViewConstants.ATTRIBUTE_HTTPREFERRER,
|
|
||||||
get: => @attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER].getValue()
|
|
||||||
set: (value) => @attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER].setValue value
|
|
||||||
enumerable: true
|
|
||||||
|
|
||||||
# The purpose of this mutation observer is to catch assignment to the src
|
# 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
|
# 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
|
# where the webview guest has crashed and navigating to the same address
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue