From 64edede20dfa3a14624aaff3978ed37cdfc20406 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 10 Dec 2014 11:05:51 -0800 Subject: [PATCH] Move handling of "preload" to web-view-attributes --- .../lib/web-view/web-view-attributes.coffee | 15 +++++++++++++++ atom/renderer/lib/web-view/web-view.coffee | 11 ----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/atom/renderer/lib/web-view/web-view-attributes.coffee b/atom/renderer/lib/web-view/web-view-attributes.coffee index b1a9599024..a3e97b5be4 100644 --- a/atom/renderer/lib/web-view/web-view-attributes.coffee +++ b/atom/renderer/lib/web-view/web-view-attributes.coffee @@ -170,6 +170,20 @@ class HttpReferrerAttribute extends WebViewAttribute constructor: (webViewImpl) -> super webViewConstants.ATTRIBUTE_HTTPREFERRER, webViewImpl +# Attribute that set preload script. +class PreloadAttribute extends WebViewAttribute + constructor: (webViewImpl) -> + super webViewConstants.ATTRIBUTE_PRELOAD, webViewImpl + + getValue: -> + return '' unless @webViewImpl.webviewNode.hasAttribute @name + preload = resolveUrl @webViewImpl.webviewNode.getAttribute(@name) + protocol = preload.substr 0, 5 + unless protocol in ['file:', 'asar:'] + console.error webViewConstants.ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE + preload = '' + preload + # Sets up all of the webview attributes. WebViewImpl::setupWebViewAttributes = -> @attributes = {} @@ -181,6 +195,7 @@ WebViewImpl::setupWebViewAttributes = -> @attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER] = new HttpReferrerAttribute(this) @attributes[webViewConstants.ATTRIBUTE_NODEINTEGRATION] = new BooleanAttribute(webViewConstants.ATTRIBUTE_NODEINTEGRATION, this) @attributes[webViewConstants.ATTRIBUTE_PLUGINS] = new BooleanAttribute(webViewConstants.ATTRIBUTE_PLUGINS, this) + @attributes[webViewConstants.ATTRIBUTE_PRELOAD] = new PreloadAttribute(this) autosizeAttributes = [ webViewConstants.ATTRIBUTE_MAXHEIGHT diff --git a/atom/renderer/lib/web-view/web-view.coffee b/atom/renderer/lib/web-view/web-view.coffee index 89a0d4488d..c30d04e739 100644 --- a/atom/renderer/lib/web-view/web-view.coffee +++ b/atom/renderer/lib/web-view/web-view.coffee @@ -182,17 +182,6 @@ class WebViewImpl userAgentOverride: @userAgentOverride for attributeName, attribute of @attributes params[attributeName] = attribute.getValue() - if @webviewNode.hasAttribute webViewConstants.ATTRIBUTE_PRELOAD - preload = @webviewNode.getAttribute webViewConstants.ATTRIBUTE_PRELOAD - # Get the full path. - a = document.createElement 'a' - a.href = preload - params.preload = a.href - # Only support file: or asar: protocol. - protocol = params.preload.substr 0, 5 - unless protocol in ['file:', 'asar:'] - delete params.preload - console.error webViewConstants.ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE params attachWindow: (guestInstanceId) ->