]> khamidou — GitHub mirrors - electron.git/commitdiff
Pass "preload" attribute to GuestViewManager
authorCheng Zhao <zcbenz@gmail.com>
Thu, 6 Nov 2014 06:35:32 +0000 (14:35 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 6 Nov 2014 06:35:32 +0000 (14:35 +0800)
atom/renderer/lib/web-view.coffee

index 456ce931f15ed1964766d5735acef3a43b97ee95..ee11683d9a529006c49297409b99c3f9793e510d 100644 (file)
@@ -21,6 +21,7 @@ WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth'
 WEB_VIEW_ATTRIBUTE_PARTITION = 'partition'
 WEB_VIEW_ATTRIBUTE_NODEINTEGRATION = 'nodeintegration'
 WEB_VIEW_ATTRIBUTE_PLUGINS = 'plugins'
+WEB_VIEW_ATTRIBUTE_PRELOAD = 'preload'
 AUTO_SIZE_ATTRIBUTES = [
   WEB_VIEW_ATTRIBUTE_AUTOSIZE,
   WEB_VIEW_ATTRIBUTE_MAXHEIGHT,
@@ -38,6 +39,8 @@ ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE = '<webview>: ' +
     'contentWindow is not available at this time. It will become available ' +
     'when the page has finished loading.'
 ERROR_MSG_INVALID_PARTITION_ATTRIBUTE = 'Invalid partition attribute.'
+ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE =
+    'Only "file:" or "asar:" protocol is supported in "preload" attribute.'
 
 # Represents the state of the storage partition.
 class Partition
@@ -379,6 +382,17 @@ class WebView
       storagePartitionId: storagePartitionId
       nodeIntegration: @webviewNode.hasAttribute WEB_VIEW_ATTRIBUTE_NODEINTEGRATION
       plugins: @webviewNode.hasAttribute WEB_VIEW_ATTRIBUTE_PLUGINS
+    if @webviewNode.hasAttribute WEB_VIEW_ATTRIBUTE_PRELOAD
+      preload = @webviewNode.getAttribute WEB_VIEW_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 ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE
     guestViewInternal.createGuest 'webview', params, (guestInstanceId) =>
       @pendingGuestCreation = false
       unless @elementAttached