WebViewImpl = require './web-view'
guestViewInternal = require './guest-view-internal'
webViewConstants = require './web-view-constants'
+remote = require 'remote'
# Attribute objects.
# Default implementation of a WebView attribute.
handleMutation: (oldValue, newValue) ->
return unless @webViewImpl.guestInstanceId
- guestViewInternal.setAllowTransparency @webViewImpl.guestInstanceId, @webViewImpl.attributes[webViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY].getValue()
+ guestViewInternal.setAllowTransparency @webViewImpl.guestInstanceId, @getValue()
# Attribute used to define the demension limits of autosizing.
class AutosizeDimensionAttribute extends WebViewAttribute
# on every guest-initiated navigation.
@setValueIgnoreMutation oldValue
return
- @webViewImpl.parseSrcAttribute()
+ @parse()
# 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
attributeFilter: [@name]
@observer.observe @webViewImpl.webviewNode, params
+ parse: ->
+ if not @webViewImpl.elementAttached or
+ not @webViewImpl.attributes[webViewConstants.ATTRIBUTE_PARTITION].validPartitionId or
+ not @.getValue()
+ return
+
+ unless @webViewImpl.guestInstanceId?
+ if @webViewImpl.beforeFirstNavigation
+ @webViewImpl.beforeFirstNavigation = false
+ @webViewImpl.createGuest()
+ return
+
+ # Navigate to |this.src|.
+ httpreferrer = @webViewImpl.attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER].getValue()
+ urlOptions = if httpreferrer then {httpreferrer} else {}
+ remote.getGuestWebContents(@webViewImpl.guestInstanceId).loadUrl @getValue(), urlOptions
+
# Attribute specifies HTTP referrer.
class HttpReferrerAttribute extends WebViewAttribute
constructor: (webViewImpl) ->
super webViewConstants.ATTRIBUTE_HTTPREFERRER, webViewImpl
handleMutation: (oldValue, newValue) ->
- @webViewImpl.parseSrcAttribute()
+ SrcAttribute::parse.call this
# Sets up all of the webview attributes.
WebViewImpl::setupWebViewAttributes = ->
# changed.
@dispatchEvent webViewEvent
- parseSrcAttribute: ->
- if not @attributes[webViewConstants.ATTRIBUTE_PARTITION].validPartitionId or
- not @attributes[webViewConstants.ATTRIBUTE_SRC].getValue()
- return
-
- unless @guestInstanceId?
- if @beforeFirstNavigation
- @beforeFirstNavigation = false
- @createGuest()
- return
-
- # Navigate to |this.src|.
- httpreferrer = @attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER].getValue()
- urlOptions = if httpreferrer then {httpreferrer} else {}
- remote.getGuestWebContents(@guestInstanceId).loadUrl @attributes[webViewConstants.ATTRIBUTE_SRC].getValue(), urlOptions
-
createGuest: ->
return if @pendingGuestCreation
params =
return unless internal
unless internal.elementAttached
internal.elementAttached = true
- internal.parseSrcAttribute()
+ internal.attributes[webViewConstants.ATTRIBUTE_SRC].parse()
# Public-facing API methods.
methods = [