diff --git a/atom/renderer/lib/web-view/web-view-attributes.coffee b/atom/renderer/lib/web-view/web-view-attributes.coffee index a255c30669a8..93d38495a83f 100644 --- a/atom/renderer/lib/web-view/web-view-attributes.coffee +++ b/atom/renderer/lib/web-view/web-view-attributes.coffee @@ -1,6 +1,7 @@ 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. @@ -54,7 +55,7 @@ class AllowTransparencyAttribute extends BooleanAttribute 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 @@ -116,7 +117,7 @@ class SrcAttribute 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 @@ -135,13 +136,30 @@ class SrcAttribute extends WebViewAttribute 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 = -> diff --git a/atom/renderer/lib/web-view/web-view.coffee b/atom/renderer/lib/web-view/web-view.coffee index a0087826e69e..1ad9ba0f666b 100644 --- a/atom/renderer/lib/web-view/web-view.coffee +++ b/atom/renderer/lib/web-view/web-view.coffee @@ -134,22 +134,6 @@ class WebViewImpl # 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 = @@ -272,7 +256,7 @@ registerWebViewElement = -> return unless internal unless internal.elementAttached internal.elementAttached = true - internal.parseSrcAttribute() + internal.attributes[webViewConstants.ATTRIBUTE_SRC].parse() # Public-facing API methods. methods = [