Chromium Code Reviews| Index: extensions/renderer/resources/guest_view/web_view.js |
| diff --git a/extensions/renderer/resources/guest_view/web_view.js b/extensions/renderer/resources/guest_view/web_view.js |
| index 8405e38412fce3072fd339724285dc3bed34bf92..d5b44a519776ad769b84d1d4dec742e51bbf9569 100644 |
| --- a/extensions/renderer/resources/guest_view/web_view.js |
| +++ b/extensions/renderer/resources/guest_view/web_view.js |
| @@ -129,14 +129,12 @@ WebView.prototype.validateExecuteCodeCall = function() { |
| WebView.prototype.setupAutoSizeProperties = function() { |
| $Array.forEach(AUTO_SIZE_ATTRIBUTES, function(attributeName) { |
| - this.attributes[attributeName].setValue( |
| - this.webviewNode.getAttribute(attributeName)); |
| Object.defineProperty(this.webviewNode, attributeName, { |
| get: function() { |
| return this.attributes[attributeName].getValue(); |
| }.bind(this), |
| set: function(value) { |
| - this.webviewNode.setAttribute(attributeName, value); |
| + this.attributes[attributeName].setValue(value); |
| }.bind(this), |
| enumerable: true |
| }); |
| @@ -153,9 +151,8 @@ WebView.prototype.setupWebviewNodeProperties = function() { |
| getValue(); |
| }.bind(this), |
| set: function(value) { |
| - this.webviewNode.setAttribute( |
| - WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, |
| - value); |
| + this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY]. |
| + setValue(value); |
| }.bind(this), |
| enumerable: true |
| }); |
| @@ -179,7 +176,7 @@ WebView.prototype.setupWebviewNodeProperties = function() { |
| return this.attributes[WebViewConstants.ATTRIBUTE_NAME].getValue(); |
| }.bind(this), |
| set: function(value) { |
| - this.webviewNode.setAttribute(WebViewConstants.ATTRIBUTE_NAME, value); |
| + this.attributes[WebViewConstants.ATTRIBUTE_NAME].setValue(value); |
| }.bind(this), |
| enumerable: true |
| }); |
| @@ -190,25 +187,17 @@ WebView.prototype.setupWebviewNodeProperties = function() { |
| return this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].getValue(); |
| }.bind(this), |
| set: function(value) { |
| - var result = this.attributes[WebViewConstants.ATTRIBUTE_PARTITION]. |
| - setValue(value); |
| - if (result.error) { |
| - throw result.error; |
| - } |
| - this.webviewNode.setAttribute(WebViewConstants.ATTRIBUTE_PARTITION, |
| - value); |
| + this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].setValue(value); |
| }.bind(this), |
| enumerable: true |
| }); |
| - this.attributes[WebViewConstants.ATTRIBUTE_SRC].setValue( |
| - this.webviewNode.getAttribute(WebViewConstants.ATTRIBUTE_SRC)); |
| Object.defineProperty(this.webviewNode, WebViewConstants.ATTRIBUTE_SRC, { |
| get: function() { |
| return this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); |
| }.bind(this), |
| set: function(value) { |
| - this.webviewNode.setAttribute(WebViewConstants.ATTRIBUTE_SRC, value); |
| + this.attributes[WebViewConstants.ATTRIBUTE_SRC].setValue(value); |
| }.bind(this), |
| enumerable: true |
| }); |
| @@ -223,7 +212,7 @@ WebView.prototype.setupWebViewSrcAttributeMutationObserver = |
| this.srcAndPartitionObserver = new MutationObserver(function(mutations) { |
| $Array.forEach(mutations, function(mutation) { |
| var oldValue = mutation.oldValue; |
| - var newValue = this.webviewNode.getAttribute(mutation.attributeName); |
| + var newValue = this.attributes[mutation.attributeName].getValue(); |
| if (oldValue != newValue) { |
| return; |
| } |
| @@ -246,17 +235,22 @@ WebView.prototype.setupWebViewSrcAttributeMutationObserver = |
| // attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more |
| // details. |
| WebView.prototype.handleWebviewAttributeMutation = |
| - function(name, oldValue, newValue) { |
| - if (AUTO_SIZE_ATTRIBUTES.indexOf(name) > -1) { |
| - this.attributes[name].setValue(newValue); |
| + function(attributeName, oldValue, newValue) { |
| + // Certain changes (such as internally-initiated changes) to attributes should |
| + // not be handled normally. |
| + if (this.attributes[attributeName] && |
| + this.attributes[attributeName].ignoreNextMutation) { |
| + this.attributes[attributeName].ignoreNextMutation = false; |
| + return; |
| + } |
| + |
| + if (AUTO_SIZE_ATTRIBUTES.indexOf(attributeName) > -1) { |
| if (!this.guestInstanceId) { |
| return; |
| } |
| - // Convert autosize attribute to boolean. |
| - var autosize = this.webviewNode.hasAttribute( |
| - WebViewConstants.ATTRIBUTE_AUTOSIZE); |
| GuestViewInternal.setAutoSize(this.guestInstanceId, { |
| - 'enableAutoSize': autosize, |
| + 'enableAutoSize': this.attributes[WebViewConstants.ATTRIBUTE_AUTOSIZE]. |
| + getValue(), |
| 'min': { |
| 'width': parseInt(this. |
| attributes[WebViewConstants.ATTRIBUTE_MINWIDTH].getValue() || 0), |
| @@ -271,19 +265,13 @@ WebView.prototype.handleWebviewAttributeMutation = |
| } |
| }); |
| return; |
| - } else if (name == WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY) { |
| + } else if (attributeName == WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY) { |
| // We treat null attribute (attribute removed) and the empty string as |
| // one case. |
| oldValue = oldValue || ''; |
| newValue = newValue || ''; |
| - if (oldValue === newValue) { |
| - return; |
| - } |
| - this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY]. |
| - setValue(newValue != ''); |
| - |
| - if (!this.guestInstanceId) { |
| + if (oldValue === newValue || !this.guestInstanceId) { |
| return; |
| } |
| @@ -292,7 +280,7 @@ WebView.prototype.handleWebviewAttributeMutation = |
| this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY]. |
| getValue()); |
| return; |
| - } else if (name == WebViewConstants.ATTRIBUTE_NAME) { |
| + } else if (attributeName == WebViewConstants.ATTRIBUTE_NAME) { |
| // We treat null attribute (attribute removed) and the empty string as |
| // one case. |
| oldValue = oldValue || ''; |
| @@ -301,19 +289,19 @@ WebView.prototype.handleWebviewAttributeMutation = |
| if (oldValue === newValue) { |
| return; |
| } |
| - this.attributes[WebViewConstants.ATTRIBUTE_NAME].setValue(newValue); |
| + |
| if (!this.guestInstanceId) { |
| return; |
| } |
| WebViewInternal.setName(this.guestInstanceId, newValue); |
| return; |
| - } else if (name == WebViewConstants.ATTRIBUTE_SRC) { |
| + } else if (attributeName == WebViewConstants.ATTRIBUTE_SRC) { |
| // We treat null attribute (attribute removed) and the empty string as |
| // one case. |
| oldValue = oldValue || ''; |
| newValue = newValue || ''; |
| // Once we have navigated, we don't allow clearing the src attribute. |
| - // Once <webview> enters a navigated state, it cannot be return back to a |
| + // Once <webview> enters a navigated state, it cannot return to a |
| // placeholder state. |
| if (newValue == '' && oldValue != '') { |
| // src attribute changes normally initiate a navigation. We suppress |
| @@ -323,7 +311,7 @@ WebView.prototype.handleWebviewAttributeMutation = |
| this.webviewNode.setAttribute(WebViewConstants.ATTRIBUTE_SRC, oldValue); |
| return; |
| } |
| - this.attributes[WebViewConstants.ATTRIBUTE_SRC].setValue(newValue); |
| + |
| if (this.ignoreNextSrcAttributeChange) { |
| // Don't allow the src mutation observer to see this change. |
| this.srcAndPartitionObserver.takeRecords(); |
| @@ -332,19 +320,15 @@ WebView.prototype.handleWebviewAttributeMutation = |
| } |
| var result = {}; |
| this.parseSrcAttribute(result); |
| - |
| - if (result.error) { |
| - throw result.error; |
| - } |
| - } else if (name == WebViewConstants.ATTRIBUTE_PARTITION) { |
| - // Note that throwing error here won't synchronously propagate. |
| - this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].setValue(newValue); |
| + } else if (attributeName == WebViewConstants.ATTRIBUTE_PARTITION) { |
| + this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].handleMutation( |
| + oldValue, newValue); |
| } |
| }; |
| WebView.prototype.handleBrowserPluginAttributeMutation = |
| - function(name, oldValue, newValue) { |
| - if (name == WebViewConstants.ATTRIBUTE_INTERNALINSTANCEID && |
| + function(attributeName, oldValue, newValue) { |
| + if (attributeName == WebViewConstants.ATTRIBUTE_INTERNALINSTANCEID && |
| !oldValue && !!newValue) { |
| this.browserPluginNode.removeAttribute( |
| WebViewConstants.ATTRIBUTE_INTERNALINSTANCEID); |
| @@ -417,7 +401,7 @@ WebView.prototype.onSizeChanged = function(webViewEvent) { |
| minHeight = maxHeight; |
| } |
| - if (!this.webviewNode.hasAttribute(WebViewConstants.ATTRIBUTE_AUTOSIZE) || |
| + if (!this.attributes[WebViewConstants.ATTRIBUTE_AUTOSIZE].getValue() || |
| (newWidth >= minWidth && |
| newWidth <= maxWidth && |
| newHeight >= minHeight && |
| @@ -444,8 +428,6 @@ WebView.prototype.parseSrcAttribute = function(result) { |
| result.error = WebViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE; |
| return; |
| } |
| - this.attributes[WebViewConstants.ATTRIBUTE_SRC].setValue( |
| - this.webviewNode.getAttribute(WebViewConstants.ATTRIBUTE_SRC)); |
| if (!this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue()) { |
| return; |
| @@ -469,10 +451,7 @@ WebView.prototype.parseAttributes = function() { |
| if (!this.elementAttached) { |
| return; |
| } |
| - var attributeValue = this.webviewNode.getAttribute( |
| - WebViewConstants.ATTRIBUTE_PARTITION); |
| - var result = this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].setValue( |
| - attributeValue); |
| + var result = {}; |
|
Fady Samuel
2014/11/03 22:38:18
Is this necessary?
paulmeyer
2014/11/03 22:58:19
no
|
| this.parseSrcAttribute(result); |
| }; |
| @@ -480,11 +459,9 @@ WebView.prototype.createGuest = function() { |
| if (this.pendingGuestCreation) { |
| return; |
| } |
| - var storagePartitionId = |
| - this.webviewNode.getAttribute(WebViewConstants.ATTRIBUTE_PARTITION) || |
| - this.webviewNode[WebViewConstants.ATTRIBUTE_PARTITION]; |
| var params = { |
| - 'storagePartitionId': storagePartitionId |
| + 'storagePartitionId': this.attributes[ |
| + WebViewConstants.ATTRIBUTE_PARTITION].getValue() |
| }; |
| GuestViewInternal.createGuest( |
| 'webview', |
| @@ -502,13 +479,11 @@ WebView.prototype.createGuest = function() { |
| }; |
| WebView.prototype.onFrameNameChanged = function(name) { |
| - this.attributes[WebViewConstants.ATTRIBUTE_NAME].setValue(name || ''); |
| - if (this.attributes[WebViewConstants.ATTRIBUTE_NAME].getValue() === '') { |
| + name = name || ''; |
| + if (name === '') { |
| this.webviewNode.removeAttribute(WebViewConstants.ATTRIBUTE_NAME); |
| } else { |
| - this.webviewNode.setAttribute( |
| - WebViewConstants.ATTRIBUTE_NAME, |
| - this.attributes[WebViewConstants.ATTRIBUTE_NAME].getValue()); |
| + this.attributes[WebViewConstants.ATTRIBUTE_NAME].setValue(name); |
| } |
| }; |
| @@ -543,7 +518,7 @@ WebView.prototype.onLoadCommit = function( |
| this.currentEntryIndex = currentEntryIndex; |
| this.entryCount = entryCount; |
| this.processId = processId; |
| - var oldValue = this.webviewNode.getAttribute(WebViewConstants.ATTRIBUTE_SRC); |
| + var oldValue = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); |
| var newValue = url; |
| if (isTopLevel && (oldValue != newValue)) { |
| // Touching the src attribute triggers a navigation. To avoid |
| @@ -555,8 +530,6 @@ WebView.prototype.onLoadCommit = function( |
| }; |
| WebView.prototype.onAttach = function(storagePartitionId) { |
| - this.webviewNode.setAttribute(WebViewConstants.ATTRIBUTE_PARTITION, |
| - storagePartitionId); |
| this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].setValue( |
| storagePartitionId); |
| }; |
| @@ -564,9 +537,8 @@ WebView.prototype.onAttach = function(storagePartitionId) { |
| WebView.prototype.buildAttachParams = function(isNewWindow) { |
| var params = { |
| 'allowtransparency': this.attributes[ |
| - WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY].getValue() || false, |
| - 'autosize': this.webviewNode.hasAttribute( |
| - WebViewConstants.ATTRIBUTE_AUTOSIZE), |
| + WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY].getValue(), |
| + 'autosize': this.attributes[WebViewConstants.ATTRIBUTE_AUTOSIZE].getValue(), |
| 'instanceId': this.viewInstanceId, |
| 'maxheight': parseInt(this.attributes[WebViewConstants.ATTRIBUTE_MAXHEIGHT]. |
| getValue() || 0), |
| @@ -590,7 +562,7 @@ WebView.prototype.buildAttachParams = function(isNewWindow) { |
| }; |
| WebView.prototype.attachWindow = function(guestInstanceId, |
| - isNewWindow) { |
| + isNewWindow) { |
| this.guestInstanceId = guestInstanceId; |
| var params = this.buildAttachParams(isNewWindow); |