]> khamidou — GitHub mirrors - electron.git/commitdiff
Moved parseSrcAttribute() into the SrcAttribute object as parse()
authorCheng Zhao <zcbenz@gmail.com>
Tue, 9 Dec 2014 05:35:10 +0000 (21:35 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 9 Dec 2014 05:35:10 +0000 (21:35 -0800)
Imported from:
https://chromium.googlesource.com/chromium/src/+/3bc15760f9c7fb79cb3dd6064781c26ebbe1d5af%5E%21/

atom/renderer/lib/web-view/web-view-attributes.coffee
atom/renderer/lib/web-view/web-view.coffee

index a255c30669a8b1106eabb1db9added90cf253980..93d38495a83ff7414b77295507c39a82be0663f3 100644 (file)
@@ -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 = ->
index a0087826e69efa11ae4240206c97384c73fd9915..1ad9ba0f666ba2cbba22e10e376496e2cb6569f2 100644 (file)
@@ -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 = [