]> khamidou — GitHub mirrors - electron.git/commitdiff
Fix relative links in "src" of <webview>
authorCheng Zhao <zcbenz@gmail.com>
Wed, 10 Dec 2014 18:51:34 +0000 (10:51 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 10 Dec 2014 18:51:34 +0000 (10:51 -0800)
atom/renderer/lib/web-view/web-view-attributes.coffee

index 9df67251a0600e8d7ceee3f7506a4f57441ada96..b1a95990243d9fadf5791e2390fb6674995d48ed 100644 (file)
@@ -3,6 +3,12 @@ guestViewInternal = require './guest-view-internal'
 webViewConstants = require './web-view-constants'
 remote = require 'remote'
 
+# Helper function to resolve url set in attribute.
+a = document.createElement 'a'
+resolveUrl = (url) ->
+  a.href = url
+  a.href
+
 # Attribute objects.
 # Default implementation of a WebView attribute.
 class WebViewAttribute
@@ -107,6 +113,12 @@ class SrcAttribute extends WebViewAttribute
     super webViewConstants.ATTRIBUTE_SRC, webViewImpl
     @setupMutationObserver()
 
+  getValue: ->
+    if @webViewImpl.webviewNode.hasAttribute @name
+      resolveUrl @webViewImpl.webviewNode.getAttribute(@name)
+    else
+      ''
+
   handleMutation: (oldValue, newValue) ->
     # Once we have navigated, we don't allow clearing the src attribute.
     # Once <webview> enters a navigated state, it cannot return to a
@@ -158,9 +170,6 @@ class HttpReferrerAttribute extends WebViewAttribute
   constructor: (webViewImpl) ->
     super webViewConstants.ATTRIBUTE_HTTPREFERRER, webViewImpl
 
-  handleMutation: (oldValue, newValue) ->
-    SrcAttribute::parse.call this
-
 # Sets up all of the webview attributes.
 WebViewImpl::setupWebViewAttributes = ->
   @attributes = {}