Fix changing src would calling loadUrl for twice

This commit is contained in:
Cheng Zhao 2015-06-03 14:33:22 +08:00
parent 34cd1435b4
commit 95a8f3fc70

View file

@ -28,7 +28,7 @@ class WebViewAttribute
# Changes the attribute's value without triggering its mutation handler. # Changes the attribute's value without triggering its mutation handler.
setValueIgnoreMutation: (value) -> setValueIgnoreMutation: (value) ->
@ignoreMutation = true @ignoreMutation = true
@webViewImpl.webviewNode.setAttribute(@name, value || '') @setValue value
@ignoreMutation = false @ignoreMutation = false
# Defines this attribute as a property on the webview node. # Defines this attribute as a property on the webview node.
@ -119,6 +119,14 @@ class SrcAttribute extends WebViewAttribute
else else
'' ''
setValueIgnoreMutation: (value) ->
WebViewAttribute::setValueIgnoreMutation value
# takeRecords() is needed to clear queued up src mutations. Without it, it
# is possible for this change to get picked up asyncronously by src's
# mutation observer |observer|, and then get handled even though we do not
# want to handle this mutation.
@observer.takeRecords()
handleMutation: (oldValue, newValue) -> handleMutation: (oldValue, newValue) ->
# Once we have navigated, we don't allow clearing the src attribute. # Once we have navigated, we don't allow clearing the src attribute.
# Once <webview> enters a navigated state, it cannot return to a # Once <webview> enters a navigated state, it cannot return to a
@ -138,7 +146,10 @@ class SrcAttribute extends WebViewAttribute
setupMutationObserver: -> setupMutationObserver: ->
@observer = new MutationObserver (mutations) => @observer = new MutationObserver (mutations) =>
for mutation in mutations for mutation in mutations
@handleMutation mutation.oldValue, @getValue() oldValue = mutation.oldValue
newValue = @getValue()
return if oldValue isnt newValue
@handleMutation oldValue, newValue
params = params =
attributes: true, attributes: true,
attributeOldValue: true, attributeOldValue: true,