]> khamidou — GitHub mirrors - electron.git/commitdiff
Making Http Referrer addition better!
authorFrank Hale <frankhale@gmail.com>
Sat, 8 Nov 2014 02:54:36 +0000 (21:54 -0500)
committerFrank Hale <frankhale@gmail.com>
Sat, 8 Nov 2014 02:54:36 +0000 (21:54 -0500)
- Code cleanup

atom/browser/api/atom_api_web_contents.cc
atom/browser/api/lib/browser-window.coffee
atom/browser/lib/guest-window-manager.coffee
atom/renderer/lib/web-view.coffee

index 983d37d502f253c4e825a226cca590c723e8d88c..cf40de96e488ea3a22a5e0b539dd3ad67c61968f 100644 (file)
@@ -291,7 +291,7 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
 
   base::string16 http_referrer_;
 
-  if(options.Get("httpReferrer", &http_referrer_))
+  if (options.Get("httpreferrer", &http_referrer_))
     params.referrer = content::Referrer(GURL(http_referrer_).GetAsReferrer(), blink::WebReferrerPolicyDefault);
 
   params.transition_type = content::PAGE_TRANSITION_TYPED;
index a25672e28e1368a4c8c859af118a39fa4c6a7a5f..243ad1ac3c756ad3a798b7324864ff40004f2fdb 100644 (file)
@@ -11,8 +11,6 @@ BrowserWindow::__proto__ = EventEmitter.prototype
 BrowserWindow.windows = new IDWeakMap
 
 BrowserWindow::_init = ->
-  @urlOptions = {}
-
   # Simulate the application menu on platforms other than OS X.
   if process.platform isnt 'darwin'
     menu = app.getApplicationMenu()
@@ -86,23 +84,15 @@ BrowserWindow.fromId = (id) ->
   BrowserWindow.windows.get id
 
 # Helpers.
-BrowserWindow::loadUrl = ->
-  args = [].slice.call arguments
-  unless args.length > 1
-    args.push @urlOptions
-
-  #TODO: This needs fixing!
-  @urlOptions = args[1]
-
-  @webContents.loadUrl.apply @webContents, args
+BrowserWindow::loadUrl = (url, urlOptions={}) -> @webContents.loadUrl url, urlOptions
 
 BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
 
 # Be compatible with old API.
 BrowserWindow::restart = -> @webContents.reload()
 BrowserWindow::getUrl = -> @webContents.getUrl()
-BrowserWindow::reload = -> @webContents.reload(@urlOptions)
-BrowserWindow::reloadIgnoringCache = -> @webContents.reloadIgnoringCache(@urlOptions)
+BrowserWindow::reload = (urlOptions={}) -> @webContents.reload(urlOptions)
+BrowserWindow::reloadIgnoringCache = (urlOptions={}) -> @webContents.reloadIgnoringCache(urlOptions)
 BrowserWindow::getPageTitle = -> @webContents.getTitle()
 BrowserWindow::isLoading = -> @webContents.isLoading()
 BrowserWindow::isWaitingForResponse = -> @webContents.isWaitingForResponse()
index abd2d1b8729d10c8e31a7aa87cf6bf1c974f200c..123c3898a9d4232520d972bc90f42940aa87c85a 100644 (file)
@@ -7,11 +7,11 @@ frameToGuest = {}
 createGuest = (embedder, url, frameName, options) ->
   guest = frameToGuest[frameName]
   if frameName and guest?
-    guest.loadUrl url {}
+    guest.loadUrl url
     return guest.id
 
   guest = new BrowserWindow(options)
-  guest.loadUrl url {}
+  guest.loadUrl url
 
   # When |embedder| is destroyed we should also destroy attached guest, and if
   # guest is closed by user then we should prevent |embedder| from double
index 1c35c163ffe5b4557b9127c402841a238775e165..96abb4865728ba527352db1cc7681b294a600acb 100644 (file)
@@ -199,10 +199,10 @@ class WebView
       # No setter.
       enumerable: true
 
-    @httpReferrer = @webviewNode.getAttribute 'httpReferrer'
-    Object.defineProperty @webviewNode, 'httpReferrer',
+    @httpReferrer = @webviewNode.getAttribute 'httpreferrer'
+    Object.defineProperty @webviewNode, 'httpreferrer',
       get: => @httpReferrer
-      set: (value) => @webviewNode.setAttribute 'httpReferrer', value
+      set: (value) => @webviewNode.setAttribute 'httpreferrer', value
       enumerable: true
 
   # The purpose of this mutation observer is to catch assignment to the src
@@ -219,7 +219,7 @@ class WebView
     params =
       attributes: true,
       attributeOldValue: true,
-      attributeFilter: ['src', 'partition', 'httpReferrer']
+      attributeFilter: ['src', 'partition', 'httpreferrer']
     @srcAndPartitionObserver.observe @webviewNode, params
 
   # This observer monitors mutations to attributes of the <webview> and
@@ -253,19 +253,18 @@ class WebView
       return unless @guestInstanceId
 
       guestViewInternal.setAllowTransparency @guestInstanceId, @allowtransparency
-    else if name is 'httpReferrer'
+    else if name is 'httpreferrer'
       oldValue ?= ''
       newValue ?= ''
 
       if newValue == '' and oldValue != ''
-        @webviewNode.setAttribute 'httpReferrer', oldValue
+        @webviewNode.setAttribute 'httpreferrer', oldValue
 
       @httpReferrer = newValue
 
       result = {}
-      # I think the right thing to do if you change your referrer is to reload
-      # the src since I've bundled the referrer in with the parseSrcAttribute.
-      # I think it makes sense to do that.
+      # If the httpreferrer changes treat it as though the src changes and reload
+      # the page with the new httpreferrer.
       @parseSrcAttribute result
 
       throw result.error if result.error?
@@ -388,7 +387,7 @@ class WebView
       return
 
     if @httpReferrer
-      @urlOptions = { "httpReferrer": @httpReferrer }
+      @urlOptions = { "httpreferrer": @httpReferrer }
 
     # Navigate to |this.src|.
     remote.getGuestWebContents(@guestInstanceId).loadUrl @src, @urlOptions