Making Http Referrer addition better!

- Code cleanup
This commit is contained in:
Frank Hale 2014-11-07 21:54:36 -05:00
parent f56d1ea7b4
commit ef255db069
4 changed files with 15 additions and 26 deletions

View file

@ -291,7 +291,7 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
base::string16 http_referrer_; 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.referrer = content::Referrer(GURL(http_referrer_).GetAsReferrer(), blink::WebReferrerPolicyDefault);
params.transition_type = content::PAGE_TRANSITION_TYPED; params.transition_type = content::PAGE_TRANSITION_TYPED;

View file

@ -11,8 +11,6 @@ BrowserWindow::__proto__ = EventEmitter.prototype
BrowserWindow.windows = new IDWeakMap BrowserWindow.windows = new IDWeakMap
BrowserWindow::_init = -> BrowserWindow::_init = ->
@urlOptions = {}
# Simulate the application menu on platforms other than OS X. # Simulate the application menu on platforms other than OS X.
if process.platform isnt 'darwin' if process.platform isnt 'darwin'
menu = app.getApplicationMenu() menu = app.getApplicationMenu()
@ -86,23 +84,15 @@ BrowserWindow.fromId = (id) ->
BrowserWindow.windows.get id BrowserWindow.windows.get id
# Helpers. # Helpers.
BrowserWindow::loadUrl = -> BrowserWindow::loadUrl = (url, urlOptions={}) -> @webContents.loadUrl url, urlOptions
args = [].slice.call arguments
unless args.length > 1
args.push @urlOptions
#TODO: This needs fixing!
@urlOptions = args[1]
@webContents.loadUrl.apply @webContents, args
BrowserWindow::send = -> @webContents.send.apply @webContents, arguments BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
# Be compatible with old API. # Be compatible with old API.
BrowserWindow::restart = -> @webContents.reload() BrowserWindow::restart = -> @webContents.reload()
BrowserWindow::getUrl = -> @webContents.getUrl() BrowserWindow::getUrl = -> @webContents.getUrl()
BrowserWindow::reload = -> @webContents.reload(@urlOptions) BrowserWindow::reload = (urlOptions={}) -> @webContents.reload(urlOptions)
BrowserWindow::reloadIgnoringCache = -> @webContents.reloadIgnoringCache(@urlOptions) BrowserWindow::reloadIgnoringCache = (urlOptions={}) -> @webContents.reloadIgnoringCache(urlOptions)
BrowserWindow::getPageTitle = -> @webContents.getTitle() BrowserWindow::getPageTitle = -> @webContents.getTitle()
BrowserWindow::isLoading = -> @webContents.isLoading() BrowserWindow::isLoading = -> @webContents.isLoading()
BrowserWindow::isWaitingForResponse = -> @webContents.isWaitingForResponse() BrowserWindow::isWaitingForResponse = -> @webContents.isWaitingForResponse()

View file

@ -7,11 +7,11 @@ frameToGuest = {}
createGuest = (embedder, url, frameName, options) -> createGuest = (embedder, url, frameName, options) ->
guest = frameToGuest[frameName] guest = frameToGuest[frameName]
if frameName and guest? if frameName and guest?
guest.loadUrl url {} guest.loadUrl url
return guest.id return guest.id
guest = new BrowserWindow(options) guest = new BrowserWindow(options)
guest.loadUrl url {} guest.loadUrl url
# When |embedder| is destroyed we should also destroy attached guest, and if # When |embedder| is destroyed we should also destroy attached guest, and if
# guest is closed by user then we should prevent |embedder| from double # guest is closed by user then we should prevent |embedder| from double

View file

@ -199,10 +199,10 @@ class WebView
# No setter. # No setter.
enumerable: true enumerable: true
@httpReferrer = @webviewNode.getAttribute 'httpReferrer' @httpReferrer = @webviewNode.getAttribute 'httpreferrer'
Object.defineProperty @webviewNode, 'httpReferrer', Object.defineProperty @webviewNode, 'httpreferrer',
get: => @httpReferrer get: => @httpReferrer
set: (value) => @webviewNode.setAttribute 'httpReferrer', value set: (value) => @webviewNode.setAttribute 'httpreferrer', value
enumerable: true enumerable: true
# The purpose of this mutation observer is to catch assignment to the src # The purpose of this mutation observer is to catch assignment to the src
@ -219,7 +219,7 @@ class WebView
params = params =
attributes: true, attributes: true,
attributeOldValue: true, attributeOldValue: true,
attributeFilter: ['src', 'partition', 'httpReferrer'] attributeFilter: ['src', 'partition', 'httpreferrer']
@srcAndPartitionObserver.observe @webviewNode, params @srcAndPartitionObserver.observe @webviewNode, params
# This observer monitors mutations to attributes of the <webview> and # This observer monitors mutations to attributes of the <webview> and
@ -253,19 +253,18 @@ class WebView
return unless @guestInstanceId return unless @guestInstanceId
guestViewInternal.setAllowTransparency @guestInstanceId, @allowtransparency guestViewInternal.setAllowTransparency @guestInstanceId, @allowtransparency
else if name is 'httpReferrer' else if name is 'httpreferrer'
oldValue ?= '' oldValue ?= ''
newValue ?= '' newValue ?= ''
if newValue == '' and oldValue != '' if newValue == '' and oldValue != ''
@webviewNode.setAttribute 'httpReferrer', oldValue @webviewNode.setAttribute 'httpreferrer', oldValue
@httpReferrer = newValue @httpReferrer = newValue
result = {} result = {}
# I think the right thing to do if you change your referrer is to reload # If the httpreferrer changes treat it as though the src changes and reload
# the src since I've bundled the referrer in with the parseSrcAttribute. # the page with the new httpreferrer.
# I think it makes sense to do that.
@parseSrcAttribute result @parseSrcAttribute result
throw result.error if result.error? throw result.error if result.error?
@ -388,7 +387,7 @@ class WebView
return return
if @httpReferrer if @httpReferrer
@urlOptions = { "httpReferrer": @httpReferrer } @urlOptions = { "httpreferrer": @httpReferrer }
# Navigate to |this.src|. # Navigate to |this.src|.
remote.getGuestWebContents(@guestInstanceId).loadUrl @src, @urlOptions remote.getGuestWebContents(@guestInstanceId).loadUrl @src, @urlOptions