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 32eda061c127d38673bbc8980ac7490f03cfde20..f935eba1e4559dad5f03b6f665ec1df1d7c41182 100644 |
| --- a/extensions/renderer/resources/guest_view/web_view.js |
| +++ b/extensions/renderer/resources/guest_view/web_view.js |
| @@ -50,10 +50,6 @@ WebViewImpl.prototype.createBrowserPluginNode = function() { |
| return browserPluginNode; |
| }; |
| -WebViewImpl.prototype.getGuestInstanceId = function() { |
| - return this.guestInstanceId; |
| -}; |
| - |
| // Resets some state upon reattaching <webview> element to the DOM. |
| WebViewImpl.prototype.reset = function() { |
| // If guestInstanceId is defined then the <webview> has navigated and has |
| @@ -103,13 +99,6 @@ WebViewImpl.prototype.setupFocusPropagation = function() { |
| }.bind(this)); |
| }; |
| -// Validation helper function for executeScript() and insertCSS(). |
| -WebViewImpl.prototype.validateExecuteCodeCall = function() { |
| - if (!this.guestInstanceId) { |
| - throw new Error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); |
| - } |
| -}; |
| - |
| WebViewImpl.prototype.setupWebviewNodeProperties = function() { |
| // We cannot use {writable: true} property descriptor because we want a |
| // dynamic getter value. |
| @@ -175,40 +164,18 @@ WebViewImpl.prototype.onSizeChanged = function(webViewEvent) { |
| // Check the current bounds to make sure we do not resize <webview> |
| // outside of current constraints. |
| - var maxWidth; |
| - if (node.hasAttribute(WebViewConstants.ATTRIBUTE_MAXWIDTH) && |
| - node[WebViewConstants.ATTRIBUTE_MAXWIDTH]) { |
| - maxWidth = node[WebViewConstants.ATTRIBUTE_MAXWIDTH]; |
| - } else { |
| - maxWidth = width; |
| - } |
| + var maxWidth = this.attributes[ |
| + WebViewConstants.ATTRIBUTE_MAXWIDTH].getValue() || width; |
| + var minWidth = this.attributes[ |
| + WebViewConstants.ATTRIBUTE_MINWIDTH].getValue() || width; |
| + var maxHeight = this.attributes[ |
| + WebViewConstants.ATTRIBUTE_MAXHEIGHT].getValue() || height; |
| + var minHeight = this.attributes[ |
| + WebViewConstants.ATTRIBUTE_MINHEIGHT].getValue() || height; |
| - var minWidth; |
| - if (node.hasAttribute(WebViewConstants.ATTRIBUTE_MINWIDTH) && |
| - node[WebViewConstants.ATTRIBUTE_MINWIDTH]) { |
| - minWidth = node[WebViewConstants.ATTRIBUTE_MINWIDTH]; |
| - } else { |
| - minWidth = width; |
| - } |
| if (minWidth > maxWidth) { |
| minWidth = maxWidth; |
| } |
|
Fady Samuel
2014/11/11 00:04:21
minWidth = Math.min(minWidth, maxWidth);
https://
|
| - |
| - var maxHeight; |
| - if (node.hasAttribute(WebViewConstants.ATTRIBUTE_MAXHEIGHT) && |
| - node[WebViewConstants.ATTRIBUTE_MAXHEIGHT]) { |
| - maxHeight = node[WebViewConstants.ATTRIBUTE_MAXHEIGHT]; |
| - } else { |
| - maxHeight = height; |
| - } |
| - |
| - var minHeight; |
| - if (node.hasAttribute(WebViewConstants.ATTRIBUTE_MINHEIGHT) && |
| - node[WebViewConstants.ATTRIBUTE_MINHEIGHT]) { |
| - minHeight = node[WebViewConstants.ATTRIBUTE_MINHEIGHT]; |
| - } else { |
| - minHeight = height; |
| - } |
| if (minHeight > maxHeight) { |
| minHeight = maxHeight; |
| } |
|
Fady Samuel
2014/11/11 00:04:21
minHeight = Math.min(minHeight, maxHeight);
|
| @@ -226,15 +193,6 @@ WebViewImpl.prototype.onSizeChanged = function(webViewEvent) { |
| } |
| }; |
| -// Returns if <object> is in the render tree. |
| -WebViewImpl.prototype.isPluginInRenderTree = function() { |
| - return !!this.internalInstanceId && this.internalInstanceId != 0; |
| -}; |
| - |
| -WebViewImpl.prototype.hasNavigated = function() { |
| - return !this.beforeFirstNavigation; |
| -}; |
| - |
| WebViewImpl.prototype.parseSrcAttribute = function() { |
| if (!this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].validPartitionId || |
| !this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue()) { |
| @@ -255,13 +213,6 @@ WebViewImpl.prototype.parseSrcAttribute = function() { |
| this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue()); |
| }; |
| -WebViewImpl.prototype.parseAttributes = function() { |
| - if (!this.elementAttached) { |
| - return; |
| - } |
| - this.parseSrcAttribute(); |
| -}; |
| - |
| WebViewImpl.prototype.createGuest = function() { |
| if (this.pendingGuestCreation) { |
| return; |
| @@ -356,7 +307,7 @@ WebViewImpl.prototype.attachWindow = function(guestInstanceId) { |
| this.guestInstanceId = guestInstanceId; |
| var params = this.buildAttachParams(); |
| - if (!this.isPluginInRenderTree()) { |
| + if (!this.internalInstanceId) { |
| return true; |
| } |
| @@ -398,16 +349,26 @@ WebViewImpl.prototype.clearData = function() { |
| $Function.apply(WebViewInternal.clearData, null, args); |
| }; |
| -// Injects JavaScript code into the guest page. |
| -WebViewImpl.prototype.executeScript = function(var_args) { |
| - this.validateExecuteCodeCall(); |
| +// Shared implementation of executeScript() and insertCSS(). |
| +WebViewImpl.prototype.executeCode = function(func, args) { |
| + if (!this.guestInstanceId) { |
| + window.console.error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); |
| + return; |
| + } |
| + |
| var webviewSrc = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); |
| if (this.baseUrlForDataUrl != '') { |
| webviewSrc = this.baseUrlForDataUrl; |
| } |
| - var args = $Array.concat([this.guestInstanceId, webviewSrc], |
| - $Array.slice(arguments)); |
| - $Function.apply(WebViewInternal.executeScript, null, args); |
| + |
| + args = $Array.concat([this.guestInstanceId, webviewSrc], |
| + $Array.slice(args)); |
| + $Function.apply(func, null, args); |
| +} |
| + |
| +// Injects JavaScript code into the guest page. |
| +WebViewImpl.prototype.executeScript = function(var_args) { |
| + this.executeCode(WebViewInternal.executeScript, $Array.slice(arguments)); |
| }; |
| // Initiates a find-in-page request. |
| @@ -453,14 +414,7 @@ WebViewImpl.prototype.go = function(relativeIndex, callback) { |
| // Injects CSS into the guest page. |
| WebViewImpl.prototype.insertCSS = function(var_args) { |
| - this.validateExecuteCodeCall(); |
| - var webviewSrc = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); |
| - if (this.baseUrlForDataUrl != '') { |
| - webviewSrc = this.baseUrlForDataUrl; |
| - } |
| - var args = $Array.concat([this.guestInstanceId, webviewSrc], |
| - $Array.slice(arguments)); |
| - $Function.apply(WebViewInternal.insertCSS, null, args); |
| + this.executeCode(WebViewInternal.insertCSS, $Array.slice(arguments)); |
| }; |
| // Indicates whether or not the webview's user agent string has been overridden. |
| @@ -594,7 +548,7 @@ function registerWebViewElement() { |
| } |
| if (!internal.elementAttached) { |
| internal.elementAttached = true; |
| - internal.parseAttributes(); |
| + internal.parseSrcAttribute(); |
| } |
| }; |
| @@ -664,8 +618,6 @@ WebViewImpl.prototype.maybeGetChromeWebViewEvents = function() {}; |
| // Implemented when the experimental WebView API is available. |
| WebViewImpl.maybeGetExperimentalAPIs = function() {}; |
| -WebViewImpl.prototype.maybeGetExperimentalEvents = function() {}; |
| -WebViewImpl.prototype.setupExperimentalContextMenus = function() {}; |
| // Exports. |
| exports.WebViewImpl = WebViewImpl; |