]> khamidou — GitHub mirrors - electron.git/commitdiff
Move handling of "preload" to web-view-attributes
authorCheng Zhao <zcbenz@gmail.com>
Wed, 10 Dec 2014 19:05:51 +0000 (11:05 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 10 Dec 2014 19:05:51 +0000 (11:05 -0800)
atom/renderer/lib/web-view/web-view-attributes.coffee
atom/renderer/lib/web-view/web-view.coffee

index b1a95990243d9fadf5791e2390fb6674995d48ed..a3e97b5be4bada7aa5a940c5dc1b2347c4933bf7 100644 (file)
@@ -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
index 89a0d4488db60248d9d73df8aaacf11786f2be2f..c30d04e7392a80523e9649853c9e21ad1866348c 100644 (file)
@@ -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) ->